1

`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. `

adhdinHD
  • 31
  • 1
  • 5
  • Did you try using the Features -> Face ID menu in the iOS Simulator? – HangarRash Nov 29 '22 at 04:39
  • Yes I did - I have done exactly that, but that does not solve the issue. I should add that I also added the plist.info as well, so I cannot think of what I could be doing wrong right now. – adhdinHD Nov 29 '22 at 18:15

2 Answers2

1

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

adhdinHD
  • 31
  • 1
  • 5
0

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

  • Thank you for your comment. I have checked the "Enrolled" option, but the problem is that the grey box isn't popping up at all, so after checking Enrolled and I check "Matching" or "Non matching" face, nothing happens because that cue doesn't come up – adhdinHD Nov 29 '22 at 17:44
  • @adhdinHD did you add the permission in infoPlist to use authentication ? – M. Umar Farooq Nov 30 '22 at 06:37
  • Yes, I added the permission to infoPlist. That is not the root of my problem. – adhdinHD Nov 30 '22 at 19:08