我正在尝试集成cordova-plugin-sms
插件以接收和读取短信。观察程序已成功启动,但 onSMSArrive
回调未能执行。我正在检查是否允许PERMISSION.READ_SMS,如果我没有使用户授予相同的权限。
我正在像这样注册事件监听器
platform.ready().then(() => {
document.addEventListener('onSMSArrive', function(e: any) {
var sms = e.data;
console.log("received sms " + JSON.stringify( sms ));
alert("message received");
if (sms.address == 'IG-TAGORE') //look for your message address
{
this.otp = sms.body.substr(0,4);
this.stopSMS();
this.verify_otp();
}
});
this.receiveSMS();
});
这就是我启动手表的方式
if(window.SMS) window.SMS.startWatch(function() {
alert("watch started")
}, function(){
alert('failed to start watch');
});
else {
alert('plugin not ready');
}
依赖版本
"cordova-plugin-sms": "^1.0.5",
"ionic-angular": "3.9.2",
"@angular/core": "5.2.11",
"@ionic-native/core": "~4.18.0"