Is it correct to check FaceID?

Sorry, the inaccessibility of the iPhone-X.

After launching the iPhone-X, everyone wants their application to be compatible with iOS11 and touchID, but the problem is that the developer is testing the touch identifier too expensive.

I don’t have an iPhone for code verification, but can I test it in an iOS simulator?

let context = LAContext()
if ( context.biometryType == .typeFaceID ) {
      // Face ID
}
if ( context.biometryType == .typeTouchID) {
     // Touch ID
} else {
    // Stone Age
}
+4
source share
1 answer

You can also test it without a device. Use the Face ID simulator to test your code, and it will behave similarly in the iPhone-X.

The simulator does not recognize the face, but allows you to simulate the matching and mismatched edges, if you include the option Enrolledof Face ID.

Add the following code to the view controller and try Face-ID

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)) {

            if let laError = error {
                print("laError - \(laError)")
                return
            }

            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")
                        }
                    }

                })
            })
        }


    }
}


FaceID .

enter image description here


, .

.

:

enter image description here


:

enter image description here

+9

Source: https://habr.com/ru/post/1688940/


All Articles