10

I am working on a log in process for a mobile app built in react-native... https://files.slack.com/files-pri/T039NS2ED-FHARU61LH/image_from_ios.jpg

I want to have some sort of "From messages tab" that auto fills my passcode. I was wondering if anyone knew something that could lead me in the right direction about this.

rabiaasif
  • 305
  • 3
  • 6
  • 21
  • 1
    Doing this kind of thing is going to be nearly impossible on newer Android apps, as access to SMS messages has been greatly reduced for privacy. See https://android-developers.googleblog.com/2019/01/reminder-smscall-log-policy-changes.html – Gabe Sechan Apr 02 '19 at 19:34
  • @GabeSechan Look at the screen shot, does ios do this automatically and it it simply not done automatically for android (the photo is from the app my team made from an ios device) – rabiaasif Apr 02 '19 at 20:46

2 Answers2

19

For android you can try this npm

https://github.com/CentaurWarchief/react-native-android-sms-listener

https://github.com/Bruno-Furtado/react-native-sms-retriever

https://www.npmjs.com/package/react-native-get-sms-android

IOS sms reading is not possible but i have read this stackoverflow answer But I have no idea how to implement that! Automatic OTP verification in iOS?.

Vishal Dhanotiya
  • 2,512
  • 1
  • 13
  • 32
  • 3
    @SilambarasanRaman from iOS 12.0 onwards and from around RN v0.59.1 you can just use `` and as soon as you get the sms keyboard will show the otp. Very easy :) – Sagar Khatri Nov 26 '19 at 10:50
  • When I test this on android simulator my text input is not automatically updated I can only copy the value from SMS. Do you know what it could be? Is this only iOS feature? Is there something similar for android? @SagarKhatri – cinemanja Apr 13 '20 at 15:13
  • @mohwarf You need real device. – Sagar Khatri Apr 14 '20 at 07:00
0

for iOS, I've been struggling quite hard.

You have to put textContentType="oneTimeCode" and keyboardType="numeric" on your TextInput. If you need to handle the code, also add a onChangeText prop to the TextInput

and FINALLY, the most important, if you don't see iOS poping up your code coming from SMS, check which message you're sending. In my case, in French,

  • Veuillez saisir le code ${code} dans l'application is working
  • Veuillez entrer ce code dans l'application : ${code} is NOT working

I've been checking RN side for hours, and finally changing the SMS was the solution.

arnaudambro
  • 2,403
  • 3
  • 25
  • 51