React Native How to auto fetched the OTP in the textfield from the mobile sms, should support both ios and android?
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.
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.
Native support added for react-native versions 0.66+!!
Android now has autoComplete="sms-otp"
prop.
<TextInput
...
autoComplete="sms-otp" // android
textContentType="oneTimeCode" // ios
/>
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"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With