How to Show Verification Code Suggestion on Keyboard from Message

How to show verification code suggestion on keyboard from Message

Review WWDC 2018 Session 204 - Automatic Strong Passwords and Security Code AutoFill.

You will need to use a UITextField for entry and the system keyboard (no custom controls) and set the textContentType on it to .oneTimeCode (new in iOS 12).

let securityCodeTextField = UITextField()
securityCodeTextField.textContentType = .oneTimeCode

The operating system will detect verification codes from Messages automatically (messages that contain the word "code" or "passcode") with this UITextContentType set.

What is the correct format for SMS OTP to read by my keypad? iOS

Here is the documentation about password autofill. It says to actually test it out yourself by sending out a text message:

To test the format of your SMS code for different languages, text a message to yourself. If you receive a message with an underlined security code, tap on the code. If a Copy Code option appears, the system has recognized your code.

However, from other developers who have tested out it seems SMS containing these formats work fine:

your passcode is:123456

or

12345 is your code to log in.

iOS 12 OTP keyboard suggestion

Okay. This is what I could find out. Regarding the code, it is enough that I described above. Additional settings on the client is not required. But you need to pay attention to the text of the SMS message. As an example, I attached two messages.

first pic
In the first message, our code is defined by the system as a phone number. We can even call it if we click on it. But why do we need to call a one-time code? :)

second pic
In the second image, the code is defined as one-time, just what we need. If we click on it, the system will offer to copy it to the clipboard.

What is the difference? Unfortunately, it is not completely clear by what rule the text is parsed in SMS. But we can check your text in the following way:

If you set a property textContentType to your text field and nothing works for you, the first thing you need to check is whether the operating system determines the code correctly. To do this, simply go to the message application and check the code:

  1. blue font color with underscore - the system did not recognize
    one-time code.
  2. black font color (as default) with a gray underscore - it's okay!

At the end, in the first case, you should check the text of the message for the contents of incorrect characters.

PS Just a couple of examples of correct and incorrect SMS:

  • SMS-code: 12345 £ correct
  • SMS-code: 12345 $ correct
  • SMS-code: 12345 № correct
  • SMS-code №1: 12345 incorrect

How to add auto fill suggestion for otp

1.Add the following to edittext in xml:

 android:autofillHints="smsOTPCode"
android:importantForAutofill="yes"

2.Enable the autofill service by navigating to Settings > Google > Autofill > Sms verification codes > Autofill service.

Note: This solution will work on android 8 and above.



Related Topics



Leave a reply



Submit