How to send SMS message in ionic 3 using Cordova plugin?(android and IOS)

Hi, I am going teach about how to send SMS message in ionic 3 and Angular 4.

First, we want to install the Cordova and ionic Native Plugin.
                   $ ionic cordova plugin add cordova-sms-plugin
                   $ npm install --save @ionic-native/sms
Home.html  
      <ion-header>
          <ion-navbar>
             <ion-title>
                   SMS
             </ion-title>
           </ion-navbar>
       </ion-header>
      <ion-content padding fullscreen="true">
            <div style="margin-top: 3cm">
                 <ion-list>
                    <ion-item>
                        <ion-label floating>Message</ion-label>
                     <ion-input type="text"  name="message" [(ngModel)]="message"></ion-input>
                     </ion-item>
                  </ion-list>
            <div text-center>
          <button ion-button (tap)="send()">Send</button>
            </div>
          </div>
       </ion-content>
app.module.ts
     import { SMS } from '@ionic-native/sms';
     providers: [
    ...
    ...
    SMS,
    ...
     ]
Html.ts
import { Component } from '@angular/core';
import {NavController, ToastController} from 'ionic-angular';
import { SMS } from '@ionic-native/sms';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'})
export class HomePage {
  message:any;
  constructor(private sms: SMS,public toastCtrl: ToastController) {
    this.message = '';
  }

  send(){
    this.sms.send("9XXXXXXXX3", this.message)
      .then(()=>{
        let toast = this.toastCtrl.create({
          message: 'Message send successfully',
          duration: 3000        });
        toast.present();
      },()=>{
        let toast = this.toastCtrl.create({
          message: 'Failure',
          duration: 3000        });
        toast.present();
      });
  }
}



How to send SMS message in ionic 3 using Cordova plugin?(android and IOS) How to send SMS message in ionic 3 using Cordova plugin?(android and IOS) Reviewed by Sudhan on October 09, 2017 Rating: 5

7 comments:

  1. not working.. error showed like this
    ionic Native: tried calling SMS.send, but Cordova is not available. Make sure to a) run in a real device or simulator and b) include cordova.js in your index.html

    ReplyDelete
  2. even i was added cordova.js in index.html... Please help me to resolve this

    ReplyDelete
  3. before send adding
    var options = {
    replaceLineBreaks: false, // true to replace \n by a new line, false by default
    android: {
    intent: 'INTENT' // send SMS with the native android SMS messaging
    //intent: '' // send SMS without opening any other app
    }
    };
    and

    this.sms.send("04125802176", this.message,options)

    with intent="" does not work for me either

    ReplyDelete
    Replies
    1. excuse

      intent: 'INTENT' // send SMS with the native android SMS messaging

      not work

      Delete
  4. I Find it very informative about sms marketing.Thanks for sharing such great information. hope you keep sharing such kind of information software to send bulk SMS

    ReplyDelete
  5. sms gateway appSMS Gateway Provider - If you are confused for how to send bulk SMS? Then download the best SMS gateway apps for Android from SMS-Api-Gateway. It helps you to send bulk SMS.

    ReplyDelete
  6. Best information about software.Thanks for sharing such great information. hope you keep sharing such kind of information Android Bulk sms sender

    ReplyDelete

Powered by Blogger.