【发布时间】:2021-09-20 06:42:49
【问题描述】:
iOS 使用ASCredentialIdentityStore 来保存凭据身份,并为用户提供点击它们并获取各自凭据的机会。
save credential identities 到 ASCredentialIdentityStore 的正确语法是什么?
我试过这样:
let store = ASCredentialIdentityStore.shared
let passwordIdentity = ASPasswordCredentialIdentity(serviceIdentifier: ASCredentialServiceIdentifier(identifier: "stackoverflow.com", type: .URL), user: "userTest", recordIdentifier: nil)
store.saveCredentialIdentities([passwordIdentity]) { (success, error) in
if success {
//great
} else if let err = error {
//(.error(err))
}
}
错误:
- 源文件中的编辑器占位符(这显示在 saveCredentialIdentities 调用中的错误参数中。) 注意:我遇到的另一个错误是通过在凭据身份参数周围加上括号来解决的。
我知道,我需要在 SWIFT 上做得更好,我应该做很多阅读,但我只是想让这个自动填充提供程序发挥作用。任何帮助表示赞赏。
【问题讨论】:
-
可能您没有将占位符文本
identities替换为您要保存的值,这将是一个包含您的身份[passwordIdentity]的数组 -
啊,我之前保存了身份,忘记切换回来,因此“找不到”。之前有两个单独的错误。然而,括号解决了这个问题,所以谢谢。我仍然有“源文件中的编辑器占位符”错误。将编辑我的问题以更清楚地表明这一点。
-
占位符文本只是指 Xcode 作为代码完成的一部分放入的文本;您需要用您的代码替换灰色占位符文本。
-
我已经尝试在成功和错误正文中进行打印等。结果相同。该错误似乎出现在这一行的错误声明中: store.saveCredentialIdentities([passwordIdentity]) { (success, error)
-
尝试删除并重新输入该行。有时 Xcode 会感到困惑 - 这表示编辑器提供了您尚未替换的占位符文本。