sej*_*ejn 9 textinput react-native
我正在使用来自react-native的Textinput。如何将 otp 或代码自动粘贴到文本输入框中。
Ish*_*dun -5
最简单的方法是使用内置的短信监听包。
https://www.npmjs.com/package/react-native-android-sms-listener
https://www.npmjs.com/package/react-native-otp-verify
如果您使用的是react-native-android-SMS-listner包,您可以使用如下代码。
let subscription = SmsListener.addListener(message => {
let verificationCodeRegex = /Your verification code: ([\d]{6})/
if (verificationCodeRegex.test(message.body)) {
let verificationCode = message.body.match(verificationCodeRegex)[1]
YourPhoneVerificationApi.verifyPhoneNumber(
message.originatingAddress,
verificationCode
).then(verifiedSuccessfully => {
if (verifiedSuccessfully) {
subscription.remove()
return
}
if (__DEV__) {
console.info(
'Failed to verify phone `%s` using code `%s`',
message.originatingAddress,
verificationCode
)
}
})
}
})
Run Code Online (Sandbox Code Playgroud)
如果您使用的是react-native-otp-verify,您可以按照以下教程进行操作
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
19326 次 |
| 最近记录: |