react-native-otp-verify
react-native-otp-verify copied to clipboard
otpHandler Once works Once does not work [Android]
Hi, I am testing the opt in release version.
And I noticed that this function sometimes works and sometimes does not work otpHandler. What am I doing wrong?
getHash = () =>
RNOtpVerify.getHash()
.then(console.log)
.catch(console.log);
startListeningForOtp = () =>
RNOtpVerify.getOtp()
.then(p => RNOtpVerify.addListener(this.otpHandler))
.catch(p => console.log(p));
otpHandler = message => {
console.log('the message is : ', message);
const otp = message.match(/(\d+)/)[0];
this.setState({otp});
RNOtpVerify.removeListener();
Keyboard.dismiss();
};
componentDidMount() {
if (Platform.OS === 'android') {
this.getHash();
this.startListeningForOtp();
}
componentWillUnmount() {
RNOtpVerify.removeListener();
}
You could try do something like this: this.startListeningForOtp(); // this method start the startListeningForOtp = () => \ RNOtpVerify.getOtp() \ .then(p => RNOtpVerify.addListener(this.otpHandler)) \ .catch(p => console.log(p)); \ RNOtpVerify.removeListener();
it work for me.. after you recived a message you need to remove the old Listener and add new Listener
@David-moonsite what is the issue that you get
does this package support ios?
@Irfanwani No, It's only support android.