我正在尝试使用Ionic SMS插件获取短信,但它无法正常工作。我安装了这个依赖项:
"@ionic-native/sms": "^4.2.1"
短信的国家/地区代码是否有任何问题?
这是我的.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 {
number: string = "";
message: string = "";
constructor(public navCtrl: NavController,public sms: SMS,private toastCtrl:
ToastController) {}
sendTextMessage() {
this.sms.send(this.number, this.message).then((result) => {
let successToast = this.toastCtrl.create({
message: "Text message sent successfully! :)",
duration: 3000
})
successToast.present();
}, (error) => {
let errorToast = this.toastCtrl.create({
message: "Text message not sent. :(",
duration: 3000
})
errorToast.present();
});
}
}
这是我的HTML代码:
<ion-content padding>
<ion-card>
<ion-item>
<ion-label stacked>Phone Number</ion-label>
<ion-input [(ngModel)]="number" type="text"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>Message</ion-label>
<ion-textarea [(ngModel)]="message"></ion-textarea>
</ion-item>
<ion-item>
<button ion-button icon-left clear item-right (click)="sendTextMessage()">
<ion-icon name="checkmark"></ion-icon>
Send
</button>
</ion-item>