SMS send multiples times to the same phone number when using cordova-sms-plugin in an Android app (Ionic 3)

#1

I have a Ionic 3 Android app used to send SMS text messages to clients/users

  • the clients/users’s list is iterated with a FOR loop. for each I have the phone number and the message to be send
  • for each vector element I call a send sms function (this.sms.send(this.vSmsComplet[i].phone, this.vSmsComplet[i].text_sms) ; )

Although all the parameters are send correctly to sms.send function a problem occures: sometimes the same SMS message is send multiples times to the same person or one person receive more than one message (the first is the correct one and the rest are messages addressed to someone else)

Details:

  1. I notices that the app send the correct number of SMS (equal to the vector length)

  2. If a user receive more than one SMS always the first one is the correct one addressed to him

  3. There are cases when users don’t receive any SMS (because the total number of send messages is correct and some users receive more than 1 SMS)

Does anyone had the same problem? Is the plugin or the way I use this.sms.send()? Should I make a pause (1-2 seconds) between calling sms.send() function.

My technologies:

Ionic:
    ionic (Ionic CLI)  : 4.0.3 (/usr/local/lib/node_modules/ionic)
    Ionic Framework    : ionic-angular 3.9.2
    @ionic/app-scripts : 3.1.10

Cordova:
    cordova (Cordova CLI) : 7.1.0
    Cordova Platforms     : android 6.3.0

System:
   NodeJS : v7.3.0 (/usr/local/bin/node)
   npm    : 3.10.10
   OS     : macOS High Sierra

Environment:
    ANDROID_HOME : not set
    cordova-sms-plugin: version="0.1.11"

The plugin:

Used according to the documentation:

a) in /src/app in app.module.ts:

import { SMS } from '@ionic-native/sms';
@NgModule({
    declarations: [
      MyApp,
      myPage1, myPage2

  ],
  imports: [
      BrowserModule,
      IonicModule.forRoot(MyApp),
      HttpModule,
      HttpClientModule,
      IonicStorageModule.forRoot()
   ],
   bootstrap: [IonicApp],
   entryComponents: [
      MyApp,
      myPage1, myPage2
   ],
   providers: [
      StatusBar,
      SplashScreen,
      {provide: ErrorHandler, useClass: IonicErrorHandler},
      config,
      SMS
   ]
  })

b) in my page:

import { SMS } from '@ionic-native/sms';

constructor(public navCtrl: NavController,
          public navParams: NavParams,
          public config: config,
          public loadingCtrl: LoadingController,
          public popoverCtrl: PopoverController,
          public appCtrl: App,
          public events: Events,
          public platform: Platform,
          private formBuilder: FormBuilder,
          public alertCtrl: AlertController,
          private sms: SMS) {}
#2

I think you could try flag your first SMS message sent as “sending/sent” until you discover the root problem. At next loop if this flag is filled you can ignore a new sending.