24

我在 WWDC 2018 上观看了这个视频What's New in Cocoa Touch并看到:

Cocoa Touch 的新功能

如何显示这些信息?

4

4 回答 4

31

查看WWDC 2018 会议 204 - 自动强密码和安全代码自动填充

您将需要使用UITextFieldfor entry 和系统键盘(无自定义控件)并将textContentType其设置为.oneTimeCode(iOS 12 中的新功能)。

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

操作系统将自动检测来自 Messages 的验证码(包含单词“code”或“passcode”的消息)UITextContentType

于 2018-06-09T17:24:04.867 回答
7

对于那些在HTML中搜索如何做到这一点的人:需要autocomplete="one-time-code"为您的输入字段添加。

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

(来自苹果文档

于 2019-06-26T10:18:21.637 回答
5

故事板

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

在此处输入图像描述

于 2020-03-15T08:45:50.433 回答
4

iOS 支持UITextField、UITextView 和任何采用 UITextInput 协议的自定义视图上的密码自动填充。系统键盘将其上的 textContentType 设置为.oneTimeCode

singleFactorCodeTextField.textContentType = .oneTimeCode

重要的

tvOS 应用程序还可以使用相同的内容类型设置支持密码自动填充。使用控制中心键盘、远程应用程序或连续互通键盘在 iOS 设备上输入密码时,自动填充 QuickType 栏会出现在键盘上方。填充登录字段时,焦点也会前进到登录按钮。

警告

如果您对安全代码输入文本字段使用自定义输入视图,iOS 将无法显示必要的自动填充 UI。

于 2018-06-27T12:28:25.690 回答