身份验证失败,再次尝试Face ID无效

时间:2018-09-10 11:04:45

标签: 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 Simulator上使用Xcode 9.4.1运行。 谢谢

1 个答案:

答案 0 :(得分:2)

之前,点击再次尝试面部识别按钮,您必须通知模拟器它应该模拟匹配还是不匹配的面部。

您可以通过选择硬件->人脸ID->匹配人脸/不匹配人脸

enter image description here