skip to Main Content

`Hi everyone, I am new to Swift and following a biometrics authentication tutorial to click a button and use Face ID or Touch ID.

Nothing happens when the biometric authentication button is pressed because canEvaluate etc do not get set to true. Details below.

variables and the relevant function


    private(set) var context = LAContext()
    @Published private(set) var biometryType: LABiometryType = .none
    private(set) var canEvaluatePolicy = false 
    @Published private(set) var isAuthenticated = false`

    func getBiometryType(){
        context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
        biometryType = context.biometryType
    }



    func authenticatedWithBiometrics() async {
        context = LAContext() 
        
        print("inside auth func")
         
  
        
        if canEvaluatePolicy{
            let reason = "to log in to your account"
            
            do{

                let success = try await context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) 
             
                print(success)
                if success {
                    DispatchQueue.main.async {
                        self.isAuthenticated = true
                        print("is authenticated", self.isAuthenticated)
                    }
                }
            }
            catch{ //if fail to authenticate, throw an error, show it, no biometry
                
                print(error.localizedDescription)
                DispatchQueue.main.async {
                    self.errorDescription = error.localizedDescription
                    self.showAlert = true
                    self.biometryType = .none
                }
            }
        }
        
    }

The issue: nothing happens when I click on the button that calls authenticatedwithbiometrics(). The function is called, the issue is that canEvaluatePolicy is FALSE and does not get set to true in getBiometryType. If I manually configure variables canEvaluatePolicy and success to true, we eventually run into the error.localizedDescription -> "biometry is not enrolled".

I’ve tried different simulators: iPhone 13, 14, 14 Pro, 14Pro Max, and SE which uses TouchID, and that also does nothing.

I’ve seen someone who had a same problem, but then it was solved by trying different simulators. That did not solve my issue.

I don’t think it’s an issue with the code because it’s literally copied from a working tutorial. Do I need to configure something in the simulator?

Can we test Face ID in simulator? this type of answer is not useful to me because I cannot even evoke the gray popup that initiates the face or touch ID process.

I am using the newest version of xcode.

Thank you. `

2

Answers


  1. Chosen as BEST ANSWER

    I know why now. You have to restart the build after checking the "Enrolled face" button for the cue to show up.


  2. You can used biometric authentication with simulator but you have to ensure you check enrolled in feature > FaceId > Enrolled after this you can check both scenarios Matching or Non Matchingenter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search