如何在应用程序中保存凭据以允许自动填充功能?

How to save credentials in app to allow AutoFill feature?

我希望我的应用程序保存用户名和密码数据,例如在第一次登录或注册时,稍后当用户尝试再次登录时,os 将提供自动填写表格的功能。因此,当应用程序提供保存在 safari 中的凭据时,这很相似,但我也希望我的应用程序在登录时保存此凭据。根据苹果文档我认为应该是 possible:

https://developer.apple.com/documentation/security/shared_web_credentials/managing_shared_credentials

If the user can create new accounts in your app, you should save the user name and password to the shared web credentials. In this way, the user can easily access the account from Safari, as well as from within your app. You can save the user’s name and password to the shared web credentials using the SecAddSharedWebCredential(::::) function as shown.

但是当我这样做时:

SecAddSharedWebCredential(domain as CFString, username as CFString, password as CFString) { error in
      if let error = error {
          print(error)
      }
}

我打印出以下错误:

Error Domain=NSOSStatusErrorDomain Code=-909 "Autofill is not enabled in Safari settings" UserInfo={NSDescription=Safari 设置中未启用自动填充}

您将在创建应用程序时通过 Apple 证明您的身份,以证明以下内容:

  1. That your app will be using the Associated Domains capability.
  2. That your Team ID is, in fact, valid.

查看本教程以获取帮助How To Secure Your App’s Passwords with Safari AutoFill in iOS 8