Open jfreak opened 7 years ago
@jfreak sorry i am not familiar with ionic 2 but i thing plugins are same for ionic 1 and 2 ionic 1 plugin work with ionic 2 also wihtout any change.. just try only controller logic will change according to ionic 2 coding standards
I have tried the necessary changes for ionic 2 but when ever a new sms arrives with set options the event or function is not fired..
Hi guys,
Can you confirm me how to inject this module in ionic 2 project. I've installed this plugin by : ionic plugin add cordova-plugin-otp-auto-verification
and also added it as node module in project by: npm i cordova-plugin-otp-auto-verification
Currently i am getting this error : Cannot find module "cordova-plugin-otp-auto-verification".
Any help would be appreciated.
Thanks Kamal
@aitckamal I have tried varies way of implementing this module but failed.. i never had any issues in injecting this module, may be this plugin works better in cordova but not in ionic 2. I am still trying to find an optimal solution to make this plugin work. So for now you can use this plugin to read otp from sms inbox https://github.com/floatinghotpot/cordova-plugin-sms and here is my code how i implemented this plugin https://github.com/jfreak/ionic-2-read-otp
Thanks for your reply @jfreak. But its not worked for me. I tried as you did in your code but document.addEventListener('onSMSArrive', this.smsArived);
is not listening onSMSArrive Event. So not able to read received SMS. And it is clearly mentioned that You can't receive SMS via this plugin on https://github.com/cordova-sms/cordova-sms-plugin#how-can-i-receive-sms
And i also didn't found any function for read SMS in Ionic native plugin https://ionicframework.com/docs/native/sms/
@aitckamal Yeah i agree with you that the plugin cannot receive SMS. But in this code you will able to read the current sms by setting up some delimiters. And i think you missed one thing.. try accepting SMS permissions for your phone for the current App. Go to the app setting for the current ionic 2 app and give permission for reading SMS.
Thanks @jfreak. Now it works fine for me. It was permission level issue. But why it does not ask for permission if permission is not given. And how can i resolve this issue. Thank you so much for helping me.
@aitckamal Use this to ask user the Permission in run time. https://ionicframework.com/docs/native/android-permissions/
Thanks @jfreak. It really helpful.
@jfreak can you send me code snippet so that it will help me to make this plugin compatible with ionic 2
@sandeepdillerao this is what i did using cordova-plugin-sms Plugin
if(window.SMS) window.SMS.startWatch(function(){
//To start sms watch listener
}, function(){
console.log('failed to start watching');
});
//Event Listener
document.addEventListener('onSMSArrive', this.smsArived);
smsArived = (result: any) => {
let smsData = result.data;
}
I am trying your code with the latest version.. I'll update you if i find any solutions for it!
@jfreak please install plugin using gitlab url not using npm repository bzc on npm i have not updated code
@sandeepdillerao ill try that
hello @jfreak,@sandeeodillerao and @aitckamal , can u please tell me how to integrate otp-auto verification in ionic 2. any help would be very appreciatable.
@abhilashWipadika, you can follow these steps to integrate otp-auto verification in ionic 2 :-
ionic plugin add cordova-plugin-otp-auto-verification
npm install --save cordova-plugin-otp-auto-verification
declare var window: any;
watchSMS() {
let _scope = this;
if(window.SMS) window.SMS.startWatch(function(){
console.log('Succeed to start watching SMS');
document.addEventListener('onSMSArrive', _scope.smsArived);
}, function(){
console.log('failed to start watching SMS');
});
}
stopWatchSMS() {
if(window.SMS) window.SMS.stopWatch(function(){
console.log('Succeed to stop watching SMS');
}, function(){
console.log('failed to stop watching SMS');
});
}
smsArived = (result: any) => {
let sms = result.data;
console.log('sms', sms);
let sender = sms.address;
console.log('sender', sender);
let otp_text = sms.body;
console.log('OTP', otp_text);
this.stopWatchSMS();
}
AndroidPermissions.PERMISSION.READ_SMS should be granted for this process. You can use Android Permission Plugin to request for READ_SMS Permission.
watchSMS() { let _scope = this; if(window.SMS) window.SMS.startWatch(function(){ console.log('Succeed to start watching SMS'); document.addEventListener('onSMSArrive', _scope.smsArived); }, function(){ console.log('failed to start watching SMS'); }); }
stopWatchSMS() { if(window.SMS) window.SMS.stopWatch(function(){ console.log('Succeed to stop watching SMS'); }, function(){ console.log('failed to stop watching SMS'); }); }
smsArived = (result: any) => { let sms = result.data; console.log('sms', sms); let sender = sms.address; console.log('sender', sender); let otp_text = sms.body; console.log('OTP', otp_text); this.stopWatchSMS(); }
using the above code for reading otp from SMS for ionic 3 getting below error can any one help
file:///android_asset/www/cordova.js: Line 312 : Error in Success callbackId: SMS329868448 : TypeError: Cannot read property 'smsArived' of null I/chromium: [INFO:CONSOLE(312)] "Error in Success callbackId: SMS329868448 : TypeError: Cannot read property 'smsArived' of null",, source: file:///android_asset/www/cordova.js
document.addEventListener('onSMSArrive', this.smsArived); declare this callback method in the constructor, that would work
Can you guide on how to integrate with ionic 2?