0

I want to read an opt from a text message and fill it automatically on the screen.

I came across this article on stackoverflow reading-otp.All the comments in there talk entirely of the options that we can use on a TextInput Field for both ios and android.

But I believe if we want to automatically fill the input without any user interaction, we need to have some kind of listener that should get the value or the message from which we can extract the otp and set the value of the field.

Related to this I got to know to this package react-native-otp-verify), but this package is only for android. It provides the listeners and the way to listen for the value and set it automatically.

But I did not find any such package or anything for IOS that allows us to set listeners that can be used to receive the value. Do I need to write a native module for this?

I created a text input as follows

<TextInput
    value={codeOTP}
    autoComplete="sms-otp" // android
    textContentType="oneTimeCode" // ios
/>

where codeOTP is a state variable. I am also aware that the structure of the message needs to be something like this

<#> Your code is: 123ABC78
FA+9qCX9VSu

Also I am not completely sure on how to generate the hash. For android we have the above mentioned package but for ios I did not find any resources.

Also there are other articles like this on stackoverflow but all of them mention solutions for android, not much is described about ios.

Hardik3296
  • 336
  • 2
  • 14
  • 1
    You can't listen for message content on iOS. It is private user data. If you set up the text field with the correct content type then iOS will automatically suggest the code from the incoming message. – Paulw11 May 24 '23 at 05:39
  • @Paulw11 if I understand correctly the only thing needed for ios is the appropriate text input property but for android I can use the react-native-verify-otp to autofill? In that case for ios how will I be able to copy the suggested value to state variable and fill the otp field? – Hardik3296 May 24 '23 at 06:25
  • 1
    You can't copy it. You have to rely on the iOS keyboard suggesting it to the user and them tapping it to put it into the text field. – Paulw11 May 24 '23 at 07:10

0 Answers0