faizalshap / react-native-otp-verify

React native sms verification without additional permissions
MIT License
251 stars 95 forks source link

otpHandler Once works Once does not work [Android] #29

Open David-moonsite opened 3 years ago

David-moonsite commented 3 years ago

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

  }
jeffreybenabou commented 3 years ago

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

faizalshap commented 1 year ago

@David-moonsite what is the issue that you get

Irfanwani commented 1 year ago

does this package support ios?

pushpender-singh-ap commented 1 year ago

@Irfanwani No, It's only support android.