React Native 如何从手机短信中自动获取文本字段中的 OTP,应该同时支持 ios 和 android?

Bin*_*sha 11 react-native

React Native 如何从移动短信中自动获取文本字段中的 OTP,是否应同时支持 ios 和 android?

小智 6

对于 Android: Google SMS Retriever API

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

对于 iOS:

您将使用TextInput 的道具textContentType

<TextInput
    value={this.state.codeOTP}
    textContentType="oneTimeCode"
/>
Run Code Online (Sandbox Code Playgroud)

您可以使用此示例进行测试:

真机测试,连接苹果账号

<TextInput
    value={this.state.codeOTP}
    textContentType="emailAddress"
/>
Run Code Online (Sandbox Code Playgroud)


Sco*_*rth 6

添加了对 React-Native 版本 0.66+ 的本机支持!

Android 现在有autoComplete="sms-otp"prop .

<TextInput
    ...
    autoComplete="sms-otp" // android
    textContentType="oneTimeCode" // ios
/>
Run Code Online (Sandbox Code Playgroud)


Ank*_*shi 1

目前,ios 还不支持使用react-native 的otp 自动读取功能。

但对于android,你可以使用这个库: https://github.com/faizalshap/react-native-otp-verify#readme