Can we test Face ID in simulator?

前端 未结 5 1803
逝去的感伤
逝去的感伤 2020-12-03 06:43

Can we test biometric authentication using the simulator?

The iPhone X Simulator shows a menu for Face ID enrollment, but after enabling that, what can I do?

5条回答
  •  一生所求
    2020-12-03 07:04

    same as give by @krunal just 2nd if should be outside of 1st.

    import LocalAuthentication
    
    class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        localAuthentication()
    }
    
    func localAuthentication() -> Void {
    
        let laContext = LAContext()
        var error: NSError?
        let biometricsPolicy = LAPolicy.deviceOwnerAuthenticationWithBiometrics
    
        if (laContext.canEvaluatePolicy(biometricsPolicy, error: &error)) {
    
    
    
            var localizedReason = "Unlock device"
            if #available(iOS 11.0, *) {
                if (laContext.biometryType == LABiometryType.faceID) {
                    localizedReason = "Unlock using Face ID"
                    print("FaceId support")
                } else if (laContext.biometryType == LABiometryType.touchID) {
                    localizedReason = "Unlock using Touch ID"
                    print("TouchId support")
                } else {
                    print("No Biometric support")
                }
            } else {
                // Fallback on earlier versions
            }
    
    
            laContext.evaluatePolicy(biometricsPolicy, localizedReason: localizedReason, reply: { (isSuccess, error) in
    
                DispatchQueue.main.async(execute: {
    
                    if let laError = error {
                        print("laError - \(laError)")
                    } else {
                        if isSuccess {
                            print("sucess")
                        } else {
                            print("failure")
                        }
                    }
                })
            })
        }
    //This should be outside of if
    
     if let laError = error {
            print("laError - \(laError)")
            return
         }
     }
    }
    

提交回复
热议问题