简体   繁体   中英

Xcode simulator does not show Face ID biometrics prompt

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

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

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 Matching在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM