IOS 11 Simulator does not allow LAContext and FaceID

I have the latest Xcode 9 GM running (September 13, 2017) and set Hardware > Face ID > Enrolled in the simulator as well as Deployment Target 11.0 . However, I get an error code of -6 LAErrorTouchIDNotAvailable .

Are there any settings that I am missing?

 let myContext = LAContext() let myLocalizedReasonString = "You are pretty" var authError: NSError? if #available(iOS 8.0, macOS 10.12.1, *) { if myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) { myContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { success, evaluateError in if success { print("// User authenticated successfully, take appropriate action") } else { print(" // User did not authenticate successfully, look at error and take appropriate action") } } } else { print(" // Could not evaluate policy; look at authError and present an appropriate message to user") } } else { print(" // Fallback on earlier versions") } 
+5
source share
5 answers

Face ID does not work in Xcode 9 GM due to a structure error. Xcode 9.1 fixes this problem.

You can test your application on the iPhone 8 simulator and make sure that it works correctly with Touch ID or launches the beta version of Xcode 9.1 and tests support for Face ID.

+8
source

I think that the iphone X faceID simulator is not working at the moment, I hope they fix it soon ...

https://forums.developer.apple.com/thread/86779

we could make a bug report to see if it speeds it up: P https://developer.apple.com/bug-reporting

+5
source

Face ID now works with Xcode 9.1. Follow these steps to test it in Simulator.

Add privacy statement to target.plist file.

enter image description here

Import the LocalAuthentication infrastructure into your project and 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") } } }) }) } } } 


Front-end authentication will prompt you for the first time to enable FaceID detection for your application.

enter image description here


Now turn on face registration and run the app to test face simulations testing.

enter image description here

Here is the simulation result for matching and inconsistent faces.

Result for face matching:

enter image description here


Result for an inconsistent face:

enter image description here

+2
source

Xcode 9.1 beta came out today when the source code should work fine in the simulator!

+1
source

According to the Apples documentation for LAContext, we need to add the NSFaceIDUsageDescription key to use String, since it will display an authorization request to use FaceId on the device.

Example add this to info.plist:

 NSFaceIDUsageDescription 

set it to String and add the text that you want to display in the request request for access to the Face ID camera.

 "Your app" request your permission to use Face ID, for you to login to your account / unlock your notes / what ever reason in the end. 

By adding this, you can go to the simulator for iPhone X, and you will be asked to specify the identifier of the person, click "Accept", and everything should work fine.

Do not forget to register biometric support for the simulator by going to Simulator -> Hardware -> Face ID / Touch ID -> Enrolled

Then you just need to click Match / Non-Matching Touch / Face ID to check your processing

Read more and check out the Apple documentation: https://developer.apple.com/documentation/localauthentication/lacontext

---- Edit ----

This worked for me in both Xcode 9.0 and 9.1

+1
source

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


All Articles