【问题标题】:Save Password Alert does not appear in Swift保存密码警报不会出现在 Swift 中
【发布时间】:2020-02-27 14:15:56
【问题描述】:

我希望在用户登录我的应用程序时显示此警报。

我为此制作了本教程。 iOS 12 Password Tools: Improving User Security and Experience

我也看过this话题。并在我的 LoginViewController.swift 中的 viewDidDisappear 或 viewWillDisappear 中使用此代码。但是这个警报根本没有出现。

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

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

}

我的 entitlements 文件是这样的(假设 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 内容类型是 usernamepasswordTextField 内容类型是 password

所以我想问一下为什么这个警报没有响起。

【问题讨论】:

  • 可能是您的设备禁用了保存密码功能(您可以在设置->通用->设备的所有密码中查看)
  • 已启用。我尝试了 2 台设备。也可以用 Safari 保存密码。
  • 用于显示警报的邮政编码。

标签: swift authentication passwords credentials associated-domains


【解决方案1】:

实现自动填充密码功能后,保存密码提醒将显示在您推送呈现(全屏)到下一个ViewController

【讨论】:

    【解决方案2】:

    在创建新帐户或更改密码时,使用 .newPassword 文本内容类型作为密码 TextField:

    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 })
    

    SecAddSharedWebCredential


    接下来,您应该将 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 目录中,或直接放在其根目录中。如果您使用 .well-known 目录,则文件的 URL 应符合以下格式:

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

    您必须使用带有有效证书且不使用任何重定向的 https:// 托管文件。

    Setting Up an App’s Associated Domains

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 2017-04-24
      • 2011-09-21
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多