【问题标题】:Implement AutoFill Credential Provider Extension in iOS14在 iOS14 中实现 AutoFill Credential Provider Extension
【发布时间】:2021-05-12 22:36:16
【问题描述】:

我正在尝试实现 AutoFill Credential Provider Extension,但是在 the video of the WWDC 提出此功能时遇到了一些问题。

是否有人已经做过可以帮助我?

现在,我添加了 AutoFill Credential Provider 功能以及 AutoFill Credential Provider 扩展,现在看起来像这样:

import AuthenticationServices

class CredentialProviderViewController: ASCredentialProviderViewController {

    override func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
    }
    
    override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
        let databaseIsUnlocked = true
        if (databaseIsUnlocked) {
            let passwordCredential = ASPasswordCredential(user: "j_appleseed", password: "apple1234")
            self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
        } else {
            self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code:ASExtensionError.userInteractionRequired.rawValue))
        }
    }

    override func prepareInterfaceToProvideCredential(for credentialIdentity: ASPasswordCredentialIdentity) {
    }

    @IBAction func cancel(_ sender: AnyObject?) {
        self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code: ASExtensionError.userCanceled.rawValue))
    }

    @IBAction func passwordSelected(_ sender: AnyObject?) {
        let passwordCredential = ASPasswordCredential(user: "j_appleseed", password: "apple1234")
        self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
    }
}

所有这些都是预先写好的,但在行

} 否则 {

self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code:ASExtensionError.userInteractionRequired.rawValue))

}

我收到黄色警告“永远不会被执行”。有人可以帮我理解这个扩展是如何工作的吗?或者有我可以遵循的指南吗?我在这个网站和互联网上的其他地方都找不到任何东西。

【问题讨论】:

  • 当您为每个视频添加此提供程序时,您是否在设备上获得了选择您的扩展程序作为自动填充提供程序的选项?我无法连接那个点。

标签: swift swiftui passwords autofill ios14


【解决方案1】:

文档或示例代码的方式并不多,而且我找不到任何教程。基本上有你已经链接到的视频,以及 ASCredentialProviderViewController 类的文档,这里是: https://developer.apple.com/documentation/authenticationservices/ascredentialproviderviewcontroller?language=objc

但是在您的代码中,应该很清楚为什么您引用的行永远不会被执行。请参阅下面的我的 cmets:

let databaseIsUnlocked = true
if (databaseIsUnlocked)    //this is always true, because you've just set it to be true
    {
    let passwordCredential = ASPasswordCredential(user: "j_appleseed", password: "apple1234")
    self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
    } else {               //so there is no "else"
        self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code:ASExtensionError.userInteractionRequired.rawValue))
    }

据推测,Apple 认为人们可能希望将“databaseIsUnlocked = true”替换为检查他们的数据库是否已解锁。如果这不适用于你,你可以忽略那一点。

【讨论】:

  • 是的,我也找不到很多东西!谢谢您的回答!我想我会按照你的建议忽略那一点
猜你喜欢
  • 1970-01-01
  • 2021-11-26
  • 2014-01-19
  • 1970-01-01
  • 2020-08-18
  • 2020-10-16
  • 2011-02-02
  • 2019-07-14
  • 2019-06-09
相关资源
最近更新 更多