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?
How it will recognize a face for authentication?
You'll need to go to Settings > Advanced and check the Show Debug Menu option. Then you'll see the option to open the web inspector for the Simulator right from that menu. With the Web Inspector open, you can debug inside the Simulator just like you could right in a desktop browser with DevTools.
Open your phone with face ID And, when your device gets unlocked using biometrics such as with face ID, it's using artificial intelligence to enable that functionality. Apple's FaceID can see in 3D. It lights up your face and places 30,000 invisible infrared dots on it and captures an image.
It's not possible to access the camera of your development machine to be used as the simulator camera. Camera functionality is not available in any iOS version and in any Simulator. You will have to use a real device for camera testing purposes.
The simulator just simulates the outcome of a correct and a failed face recognition, just like it does with Touch ID. It does not recognize faces.
Simulator does not recognise a face but allows you to simulate a matching and non-matching faces, if you've enabled Enrolled
option from Face ID
.
Add following code to your view controller and try with 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 authentication will prompt you for first time to allow FaceID detection for your app.
Now enable Face ID enrolment and run your app to test Face ID simulation Testing.
Here is simulation result for matching and non-matching faces.
Result for matching face:
Result for non-matching face:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With