简体   繁体   English

Swift 中未出现保存密码警报

[英]Save Password Alert does not appear in Swift

I want this alert to appear when the user logs in to my application.我希望在用户登录我的应用程序时出现此警报。

在此处输入图像描述

I made this tutorial for this.我为此制作了本教程。 iOS 12 Password Tools: Improving User Security and Experience iOS 12 个密码工具:提高用户安全性和体验

Also I have look this topic.我也看过这个话题。 And using this code in my LoginViewController.swift in viewDidDisappear or viewWillDisappear.并在我的 LoginViewController.swift 中的 viewDidDisappear 或 viewWillDisappear 中使用此代码。 But This alert does not appear at all.但是这个警报根本没有出现。

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    if user.id != 0 {
        usernameTextField.text = nil
        passwordTextField.text = nil
    }

}

My entitlements file like this (Suppose that twitter.com is the website of my application):我的权利文件是这样的(假设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/>

And off course my usernameTextField content type is username and passwordTextField content type is password .当然,我的usernameTextField内容类型是usernamepasswordTextField内容类型是password

So I want to ask why this alert didn't come off.所以我想问为什么这个警报没有响起。

When creating a new account or changing the password, use the.newPassword text content type for the password TextField:创建新帐户或更改密码时,使用 .newPassword 文本内容类型作为密码 TextField:

newPasswordTextField.textContentType = .newPassword
confirmPasswordTextField.textContentType = .newPassword

Enabling Password AutoFill on a Text Input View 在文本输入视图上启用密码自动填充


You can also manage iCloud Keychain Credentials using the Security.SecSharedCredentials API.您还可以使用 Security.SecSharedCredentials API 管理 iCloud 钥匙串凭据。 It will still require a domain association (entitlements):它仍然需要域关联(权利):

SecAddSharedWebCredential("your_domain.com" as CFString,
                           usernameTextField.text as CFString,
                           newPasswordTextField?.text as CFString, {(error) in })

SecAddSharedWebCredential SecAddSharedWebCredential


Next, you should add the Apple App Site Association file to your website.接下来,您应该将 Apple App Site Association 文件添加到您的网站。

Create a file named apple-app-site-association (without an extension).创建一个名为 apple-app-site-association 的文件(不带扩展名)。 Update the file to contain the JSON representation of a dictionary listing the app identifiers associated with your domain for the webcredentials service.更新文件以包含字典的 JSON 表示形式,其中列出了与您的域相关联的应用程序标识符,用于 webcredentials 服务。

{
   "webcredentials": {
       "apps": [    "D3KQX62K1A.com.example.DemoApp",
                    "D3KQX62K1A.com.example.DemoAdminApp" ]
    }
}

Use the following format for the app identifiers:对应用标识符使用以下格式:

<Team Identifier>.<Bundle Identifier>

Place this file either in your site's.well-known directory, or directly in its root directory.将此文件放在站点的.well-known 目录中,或直接放在其根目录中。 If you use the.well-known directory, the file's URL should match the following format:如果使用 .well-known 目录,则文件的 URL 应与以下格式匹配:

https://<fully qualified domain>/.well-known/apple-app-site-association

You must host the file using https:// with a valid certificate and without using any redirects.您必须使用 https:// 和有效证书托管文件,并且不使用任何重定向。

Setting Up an App's Associated Domains 设置应用的关联域

After the autofill password feature is implemented, the save password alert will show on you push or present (full screen) to next ViewController.实现自动填充密码功能后,保存密码警报将在您推送呈现(全屏)到下一个 ViewController 时显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM