这是我到现在为止所尝试的
declare let SMS:any;
............
watchSMS() {
SMS.startWatch(
success => {
let removeSmsListener = this.renderer.listen('document', 'onSMSArrive', (event) => {
this.smsArived(event);
});
},
error => {
}
);
}
stopWatch(){
SMS.stopWatch();
}
smsArived = (result: any) => {
console.log("SMS DATA 2" + this.generatedNumber);
this.stopWatch();
}
但是我收到错误SMS没有定义。我需要自动验证我在短信中收到的otp。我尝试了各种解决方案,但没有任何好转。所以我向知道如何执行此功能的人寻求帮助。在此先感谢
答案 0 :(得分:0)
导入后:
declare var SMS:any;
开始监视传入的短信/停止监视传入的短信
startWatch() {
if(SMS) SMS.startWatch(function(){
console.log('watching started');
}, function(){
console.log('failed to start watching');
});
}
stopWatch() {
if(SMS) SMS.stopWatch(function(){
console.log('watching stopped');
}, function(){
console.log('failed to stop watching');
});
}
事件监听器:
document.addEventListener('onSMSArrive', (event) => {
let sms = event.data;
});