身份验证失败,再次尝试面容 ID 不执行任何操作

map*_*008 5 ios touch-id swift face-id

我只是按照本教程通过面容 ID 对用户进行身份验证,但实际上在身份验证失败后,它不适用于“再次尝试面容 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."
    }


}
Run Code Online (Sandbox Code Playgroud)

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

lou*_*up4 6

点击Try Face Id Again按钮之前,您必须通知模拟器它是否应该模拟匹配或不匹配的面部。

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

在此处输入图片说明

  • 好的,刚刚尝试过,但很奇怪,我在点击“再次尝试 FaceID”之​​前选择了不匹配的面孔,但没有任何反应。点击后选择“不匹配”,然后出现另一个带有“再试一次”按钮的弹出窗口,这个“再试一次”按预期工作。不知道是不是模拟器的问题,因为我这里没有真机。 (2认同)