Authentication failed and Try Face Id Again does nothing
Asked Answered
T

2

6

I'm just follow this tutorial to authenticate user by Face ID but actually it's not work with "Try Face Id Again" button after authentication failed, the callback was not called and I don't know why. Here is the code:

@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."
    }


}

Running with Xcode 9.4.1 on iPhone X Simulator. Thanks

Teddie answered 10/9, 2018 at 11:4 Comment(0)
G
7

Before tapping Try Face Id Again button you have to inform the simulator if it should simulate matching or non-matching face.

You can do it by selecting Hardware->Face ID->Matching Face/Non-matching Face

enter image description here

Gamine answered 10/9, 2018 at 11:16 Comment(6)
@Teddie Ok. I've just updated the answer. It should resolve your issue.Gamine
okay, just tried but it weir, I've selected Non-matching face before tap "Try FaceID Again" but nothing happen. Select "Non-matching" after tap works, and there's another popup with "Try Again" button appear, and this "Try Again" works as expected. Don't know if it's the issue with simulator because I don't have real device here.Teddie
It's a simulator issue. Your code should work fine on real device.Gamine
It doesn't work on my iPhoneX. I can't fall in LAError.authenticationFailed situation with real device at all.Artema
This doesn't work in Xcode 12.0.1 with a simulator device running iOS 14.Antithesis
Still doesn't work in Xcode 12.5 with a iPad OS 14.5 simulator.Reshape
W
1

ANSWER: I had the same problem. Then I checked in device and it works. So this doesn't work only in simulator

Wizard answered 5/7, 2022 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.