我希望用户登录我的应用程序时显示此警报。
我为此编写了本教程。 iOS 12 Password Tools: Improving User Security and Experience
而且我也看this主题。并在viewDidDisappear或viewWillDisappear中的LoginViewController.swift中使用此代码。但是此警报根本不会出现。
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if user.id != 0 {
usernameTextField.text = nil
passwordTextField.text = nil
}
}
我的权利文件是这样的(假设twitter.com是我的应用程序的网站):
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:twitter.com</string>
<string>webcredentials:twitter.com</string>
</array>
<key>com.apple.developer.authentication-services.autofill-credential-provider</key>
<true/>
当然,我的usernameTextField内容类型是username,而passwordTextField内容类型是password。
所以我想问为什么这个警报没有发出。
newPasswordTextField.textContentType = .newPassword
confirmPasswordTextField.textContentType = .newPassword
Enabling Password AutoFill on a Text Input View
您还可以使用Security.SecSharedCredentials API管理iCloud钥匙串凭据。仍然需要域关联(权利):
SecAddSharedWebCredential("your_domain.com" as CFString, usernameTextField.text as CFString, newPasswordTextField?.text as CFString, {(error) in })
下一步,您应该将Apple App Site Association文件添加到您的网站。
创建一个名为apple-app-site-association的文件(无扩展名)。更新文件以包含字典的JSON表示形式,该字典列出与您的Webcredentials服务的域关联的应用程序标识符。
{ "webcredentials": { "apps": [ "D3KQX62K1A.com.example.DemoApp", "D3KQX62K1A.com.example.DemoAdminApp" ] } }
对应用程序标识符使用以下格式:
<Team Identifier>.<Bundle Identifier>
将此文件放置在您网站的。知名目录中,或直接放置在其根目录中。如果您使用.well-known目录,则文件的URL应与以下格式匹配:
https://<fully qualified domain>/.well-known/apple-app-site-association
您必须使用带有有效证书的https://且不使用任何重定向来托管文件。
Setting Up an App’s Associated Domains