Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native How to auto fetched the OTP in the textfield from the mobile sms,should support both ios and android?

Tags:

react-native

React Native How to auto fetched the OTP in the textfield from the mobile sms, should support both ios and android?

like image 724
Binisha Avatar asked Mar 28 '19 08:03

Binisha


People also ask

How do I send OTP to mobile number in react native?

Set up your Twilio Verify backendSign up for or log in to your Twilio account and create a new Verify Service. This is what will allow you to send SMS verification messages. Then head over to Twilio's Code Exchange and deploy the One Time Passcode (OTP) verification project.

Can I auto read OTP on mobile browsers?

Few things to be kept in mind while implementing the auto read functionality by using Web OTP API. The Web OTP API requires HTTPS origin, that is on HTTP website this functionality will not work. This functionality will work only on the chrome 84 or later on an Android device.


2 Answers

Native support added for react-native versions 0.66+!!

Android now has autoComplete="sms-otp" prop.

<TextInput
    ...
    autoComplete="sms-otp" // android
    textContentType="oneTimeCode" // ios
/>
like image 126
Scott Jungwirth Avatar answered Oct 21 '22 08:10

Scott Jungwirth


For Android : Google SMS Retriever API

https://github.com/Rajat421//react-native-sms-retriever-api#readme

For iOS :

You will use props textContentType of TextInput

<TextInput
    value={this.state.codeOTP}
    textContentType="oneTimeCode"
/>

You can test before with this example :

Tested on real device, and connect with the Apple account

<TextInput
    value={this.state.codeOTP}
    textContentType="emailAddress"
/>
like image 20
aelarassi Avatar answered Oct 21 '22 08:10

aelarassi