How to show verification code suggestion on keyboard from Message
Asked Answered
S

5

34

I watched this video What's New in Cocoa Touch at WWDC 2018 and seen:

What's New in Cocoa Touch

How to show this information?

Sit answered 9/6, 2018 at 7:49 Comment(3)
Man, this is too new to tell. What I thought was that the phone now has the intelligence and can automatically associate app name and code from messages.Alit
@Sit even i am not getting that suggestion on my iphone keyboardOlly
set your textfield to .oneTimeCode and your sms message's content also need contains OTP string too.Sit
G
42

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.

Gremlin answered 9/6, 2018 at 17:24 Comment(8)
Does text message have to be in a certain format? I have tried this in the morning an nothing showed up.Surfacetosurface
@Alix it may vary by locale, but I've found that messages like "JAL security code: XXXXXX" or "Your code is: XXXXXX" work.Gremlin
I have the format like: "3456 is your verification code" do you think that is the problemSurfacetosurface
@DaNLtR it has to be specific formart. My format is verification code is: xxxx. I think word verification or security or something like that is the keySurfacetosurface
@Alix the secret is indeed "verification" - in Hebrew as well:) thanksRudbeckia
@Alix the work code is the main word that allows apple to identify code. the word "code" and "passcode" both works. Also as JAL commented textContectType should be set to .oneTimeCodeRearward
Also you can do that via storyboard: Select your UITextField in storyboard/XIB and click on Attribute inspector. Then go to Text Input Traits section, in Content Type select One Time Code.Richard
I tried different variations in Russian and it seems only : matters, but not words, so it should be kinda Ваш код подтверждения: 1234Barricade
T
14

For those who's searching how to do that in HTML: need to add autocomplete="one-time-code" for your input field.

<input id="single-factor-code-text-field" autocomplete="one-time-code"/>

(from Apple Docs)

However, that will not work in most Android phones. For Android it's more complicated: https://web.dev/sms-otp-form/. You will need to add @domain #code to SMS text and also implement extra JS to pickup the code.

Theseus answered 26/6, 2019 at 10:18 Comment(2)
Apple’s docs seem to still say the same thing, but I was able to implement the behavior without it—or more specifically, with it set to autocomplete"off".Martres
Note that Apple is simply accepting the specification standard autocomplete value. It is not anything Apple-specific.Hydrogenolysis
B
5

Storyboard

Select UITextField > Show the Attributes inspector > Text Input Traits > Content Type > One Time Code

enter image description here

Bennie answered 15/3, 2020 at 8:45 Comment(0)
P
4

iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol. System keyboard set the textContentType on it to .oneTimeCode

singleFactorCodeTextField.textContentType = .oneTimeCode

Important

tvOS apps can also support Password AutoFill using the same content-type settings. The AutoFill QuickType bar appears above the keyboard when entering passwords with an iOS device using the Control Center keyboard, the Remote app, or the Continuity Keyboard. Focus is also advanced to the login button when the login fields are populated.

Warning

If you use a custom input view for a security code input text field, iOS cannot display the necessary AutoFill UI.

Papilionaceous answered 27/6, 2018 at 12:28 Comment(0)
F
0

if you have a website and you want to use some OTP sms authentication you should use code: or passcode: before your OTP message.

Fleischer answered 7/7, 2022 at 21:38 Comment(1)
The question is about native implementation in iOS application, not on website, but even in that case it is not clear where code (or passcode) should be added.Innocence

© 2022 - 2024 — McMap. All rights reserved.