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

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


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"
/>

Currently there is no support for ios till now for otp auto read functionality using react-native.

But for android you can use this library: https://github.com/faizalshap/react-native-otp-verify#readme


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

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

<TextInput
    ...
    autoComplete="sms-otp" // android
    textContentType="oneTimeCode" // ios
/>