当用户点击"key icon"时,如何在自动填充提示中显示密钥?



我正忙着实现密码,但我遇到了自动填充功能的问题。

根据WWDC视频(https://developer.apple.com/videos/play/wwdc2022/10092/在14:30左右),当用户点击"键图标"时,在快速输入栏中,用户会看到一个提示,让他们选择一个密码或密码来登录,而且(非常重要的!)还有"从附近的设备使用密码"的功能。

我想显示的正确模态

然而,我的应用程序(和大多数其他应用程序)只允许用户选择密码。

当前显示的模态不正确

我怎么能让我的应用程序显示第一模态(包括passkeys)?

  • 关联域已正确设置
  • 在用户名和密码字段上设置正确的textContentType
  • 根据WWDC视频
  • 正确实现ASAuthorisation
  • 我试过performRequests()performAutoFillAssistedRequests(),没有产生差异
  • 我已经尝试删除密码字段,只显示用户名字段-没有差异
  • 在iOS 16.3和16.4上测试-没有差异

使用performAutoFillAssistedRequests()时,ASAuthorizationController只允许passkey请求

根据闪亮的例子:

// AutoFill-assisted requests only support ASAuthorizationPlatformPublicKeyCredentialAssertionRequest.

PS:事后记得取消这个请求!您可以通过存储对ASAuthorizationController(例如self.authController = authController)的引用来做到这一点,当您想要取消请求时,只需调用authController.cancel()

所以完整的解决方案应该是这样的:

var authController: ASAuthorizationController?
func beginAutoFillAssistedPasskeySignIn(anchor: ASPresentationAnchor) {
self.authenticationAnchor = anchor

let publicKeyCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: domain)

// Fetch the challenge from the server. The challenge needs to be unique for each request.
let challenge = Data()
let assertionRequest = publicKeyCredentialProvider.createCredentialAssertionRequest(challenge: challenge)

// AutoFill-assisted requests only support ASAuthorizationPlatformPublicKeyCredentialAssertionRequest.
let authController = ASAuthorizationController(authorizationRequests: [ assertionRequest ] )
authController.delegate = self
authController.presentationContextProvider = self
authController.performAutoFillAssistedRequests()
self.authController = authController
}
func cancelAutoFillAssistedPasskeySignIn() {
if let authController {
authController.cancel()
self.authController = nil
}
}

最新更新