How to show verification code suggestion on keyboa

2020-05-20 07:53发布

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?

4条回答
我想做一个坏孩纸
2楼-- · 2020-05-20 08:06

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2020-05-20 08:17

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.

查看更多
在下西门庆
4楼-- · 2020-05-20 08:19

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)

查看更多
孤傲高冷的网名
5楼-- · 2020-05-20 08:29

Storyboard

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

enter image description here

查看更多
登录 后发表回答