ios – SecRequestSharedWebCredential凭据包含“密码未保存”?

我们通过函数检索任何已保存的密码:

SecRequestSharedWebCredential(NULL, NULL, ^(CFArrayRef credentials, CFErrorRef error) {
    if (!error && CFArrayGetCount(credentials)) {
        CFDictionaryRef credential = CFArrayGetValueAtIndex(credentials, 0);
        if (credential > 0) {
            CFDictionaryRef credential = CFArrayGetValueAtIndex(credentials, 0);
            NSString *username = CFDictionaryGetValue(credential, kSecAttrAccount);
            NSString *password = CFDictionaryGetValue(credential, kSecSharedPassword);
            dispatch_async(dispatch_get_main_queue(), ^{
                //Updates the UI here.
            });
        }
    }
});

问题是在IOS 9.3.3 iPhone 6 A1524上,我们收到一个名为“密码未保存”的条目提示.没有错误消息表明未找到密码.因为数组> 0,它用条目完成表单.

为什么会这样?我们认为如果您的授权域下没有存储密码,则不会出现提示.

有什么建议?

谢谢.

最佳答案 我正在viewDidLoad()中为我的Auth视图控制器检查这个.代码与上面的有点不同,从其他几个SO答案中收集.

斯威夫特3:

SecRequestSharedWebCredential(Configuration.webBaseFQDN as CFString, nil, { (credentials, error) in

    if let error = error {
        print("ERROR: credentials")
        print(error)
    }

    guard let credentials = credentials, CFArrayGetCount(credentials) > 0 else {
        // Did not find a shared web credential.
        return
    }

    guard CFArrayGetCount(credentials) == 1 else {
        // There should be exactly one credential.
        return
    }

    let unsafeCredential = CFArrayGetValueAtIndex(credentials, 0)
    let credential = unsafeBitCast(unsafeCredential, to: CFDictionary.self)

    let unsafeEmail = CFDictionaryGetValue(credential, Unmanaged.passUnretained(kSecAttrAccount).toOpaque())
    let email = unsafeBitCast(unsafeEmail, to: CFString.self) as String

    let unsafePassword = CFDictionaryGetValue(credential, Unmanaged.passUnretained(kSecSharedPassword).toOpaque())
    let password = unsafeBitCast(unsafePassword, to: CFString.self) as String

    if self.isValidEmail(email) && self.isValidPassword(password) {
        self.usedSharedWebCredentials = true
        self.doSignIn(email: email, password: password)
    }
})

对isValidEmail(_ :)和isValidPassword(_ :)的最后检查处理SecRequeestSharedWebCredential()在第一个凭证(电子邮件)中返回“未保存的密码”的情况.

希望有人可以解释为什么会发生这种情况,但如果没有,至少有一种方法可以捕获这种情况.

我还要补充一点,我已经看到了iOS 10.2.1

点赞