react-native-otp-verify icon indicating copy to clipboard operation
react-native-otp-verify copied to clipboard

otpHandler Once works Once does not work [Android]

Open David-moonsite opened this issue 4 years ago • 4 comments

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();
    
  }

David-moonsite avatar Dec 20 '20 15:12 David-moonsite

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

jeffreybenabou avatar Feb 24 '21 08:02 jeffreybenabou

@David-moonsite what is the issue that you get

faizalshap avatar Oct 30 '22 08:10 faizalshap

does this package support ios?

Irfanwani avatar Nov 22 '22 04:11 Irfanwani

@Irfanwani No, It's only support android.

pushpender-singh-ap avatar Dec 03 '22 21:12 pushpender-singh-ap