33

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
lee
  • 7,955
  • 8
  • 44
  • 60
  • 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. – Riz-waan Jun 09 '18 at 08:09
  • @lee even i am not getting that suggestion on my iphone keyboard – Arshad Shaik Jun 11 '20 at 11:43
  • set your textfield to `.oneTimeCode` and your sms message's content also need contains `OTP` string too. – lee Jun 12 '20 at 03:54

5 Answers5

40

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.

JAL
  • 41,701
  • 23
  • 172
  • 300
  • Does text message have to be in a certain format? I have tried this in the morning an nothing showed up. – Alok C Dec 03 '18 at 15:58
  • @Alix it may vary by locale, but I've found that messages like "JAL security code: XXXXXX" or "Your code is: XXXXXX" work. – JAL Dec 04 '18 at 00:30
  • I have the format like: "3456 is your verification code" do you think that is the problem – Alok C Dec 04 '18 at 14:20
  • @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 key – Alok C Mar 07 '19 at 17:20
  • @Alix the secret is indeed "verification" - in Hebrew as well:) thanks – DaNLtR Mar 10 '19 at 08:01
  • @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 .oneTimeCode – Muhammad Umair Gillani Mar 13 '19 at 10:35
  • 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. – iGhost Aug 29 '19 at 16:02
  • I tried different variations in Russian and it seems only : matters, but not words, so it should be kinda Ваш код подтверждения: 1234 – imike May 30 '21 at 10:13
10

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.

Vladimir Tolstikov
  • 2,463
  • 21
  • 14
  • 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"`. – Hein Haraldson Berg May 14 '20 at 06:50
  • Note that Apple is simply accepting the [specification standard autocomplete value](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill). It is not anything Apple-specific. – Christopher Schultz Jan 17 '23 at 21:00
5

Storyboard

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

enter image description here

Pengguna
  • 4,636
  • 1
  • 27
  • 32
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.

Ashish
  • 2,977
  • 1
  • 14
  • 32
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.

Bojan Bozovic
  • 872
  • 16
  • 35
  • 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. – Bojan Bozovic Jul 09 '22 at 14:09