Is there any way to access data from iPhone inbox(SMS) to ios application to do automatic OTP verification like the one in Android? I shall be grateful for your help.
In iOS 12 Apple has introduced feature called Security Code AutoFill
.
To use this in your app all you need to do is set UITextField
's input view’s textContentType
property oneTimeCode
.
otpTextField.textContentType = .oneTimeCode
NOTE: Security Code AutoFill will only works with System Keyboard it will not work with custom keyboard.
WWDC video
When you get OTP it will look something like this:
It is also important that the text message you receive contains something with "code" like
"your passcode is:123456"
or
"12345 is your code to log in"
something along that line.
NOT!
Your App: 12345
you can verify if the code in your text message will work with the .oneTimeCode type by tapping the underlined code in your message. If a dialog pops up that says "copy code", you are good to go. Otherwise you might need to change the text of your message.
UPDATE
From iOS 12 Apple will supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol. System keyboard set the textContentType on it to .oneTimeCode
1) Using Code
singleFactorCodeTextField.textContentType = .oneTimeCode
2) Using Storyboard/XIB
Select
UITextField
/UITextView
instoryboard/XIB
click Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.
The operating system will detect verification codes from Messages automatically with this UITextContentType
set.
Warning
If you use a custom input view for a security code input text field, iOS cannot display the necessary AutoFill UI.
For more information, you can check it on the Apple developer oneTimeCode
And also review WWDC 2018 Session 204 - Automatic Strong Passwords and Security Code AutoFill and jump to 24:28 for automatic pre-fill the OTP.
Currently for iOS 12 and above, you may use Security Code Autofill
oneTimeCodeTextField.textContentType =.oneTimeCode
However ApplePay is doing automatic verification since iOS 11 but that is not yet available to developers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With