ios - 身份验证失败,再次尝试 Face Id 什么都不做

标签 ios swift touch-id face-id

我只是按照本教程通过 Face ID 对用户进行身份验证,但实际上它在身份验证失败后无法使用“再次尝试 Face ID”按钮,回调未被调用,我不知道为什么。 这是代码:

@IBAction func touchIdAction(_ sender: UIButton) {

    print("hello there!.. You have clicked the touch ID")

    let myContext = LAContext()
    let myLocalizedReasonString = "Biometric Authntication testing !! "

    var authError: NSError?
    if #available(iOS 8.0, macOS 10.12.1, *) {
        if myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
            myContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { success, evaluateError in

                DispatchQueue.main.async {
                    if success {
                        // User authenticated successfully, take appropriate action
                        self.successLabel.text = "Awesome!!... User authenticated successfully"
                    } else {
                        // User did not authenticate successfully, look at error and take appropriate action
                        self.successLabel.text = "Sorry!!... User did not authenticate successfully"
                    }
                }
            }
        } else {
            // Could not evaluate policy; look at authError and present an appropriate message to user
            successLabel.text = "Sorry!!.. Could not evaluate policy."
        }
    } else {
        // Fallback on earlier versions

        successLabel.text = "Ooops!!.. This feature is not supported."
    }


}

在 iPhone X 模拟器上使用 Xcode 9.4.1 运行。 谢谢

最佳答案

点击再次尝试人脸识别按钮之前,您必须通知模拟器是否应该模拟匹配或不匹配的人脸。

您可以通过选择Hardware->Face ID->Matching Face/Non-matching Face

enter image description here

关于ios - 身份验证失败,再次尝试 Face Id 什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52256440/

相关文章:

ios - didReceiveRemoteNotification 将用户带到正确的 View

ios - 为什么Xcode Playground通过类似iPad的Simulator来执行liveView?

arrays - 如何按升序排列一个字典数组,然后对其他数组重新排序?

ios - 使用密码时获取 Touch ID 通知

ios - 将用户凭据存储在钥匙串(keychain)中以便使用 touchid 登录有多安全?

ios - Swift - 数组索引超出范围

ios - 无法从 CVMetalTextureGetTexture 函数获取有效的 MTLTexture

ios - 是否可以在类协议(protocol)上创建 willSet 的默认实现

ios - 如何使用 "sequential finger detection"的新 iOS 9.2 Touch ID 功能

ios - CLLocationManager() Location 在模拟器中为 nil