guhan0
guhan0

Reputation: 676

LABiometryType in iOS11 always return None

enter image description here

No matter what settings is configured in Device's passcode and touchId settings , LAContext always returns none . It is just throwing me a warning not the exception.

Its only working in XCode 9.1 Beta in iOS11.1 beta as suggested :(

Upvotes: 23

Views: 6712

Answers (4)

El0din
El0din

Reputation: 3370

In Xamarin.iOS, you need evaluate the Policy Before:

   NSError error;
   bool success = context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out error);
   if (context.BiometryType == LABiometryType.TouchId)
   {
       //Do Something
   }

Upvotes: 0

NBoymanns
NBoymanns

Reputation: 716

Got the same issue here, fixed it with the following code. But it only works with the Xcode 9.1 Beta (and iOS 11.1 beta in the simulator).

if (laContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil)) {

            if #available(iOS 11.0, *) {
                if (laContext.biometryType == LABiometryType.faceID) {
                    print("FaceId support")
                } else if (laContext.biometryType == LABiometryType.touchID) {
                    print("TouchId support")
                } else {
                    print("No Biometric support")
                }
            } else {
                // Fallback on earlier versions
            }
}

Upvotes: 4

Lee-der
Lee-der

Reputation: 93

If you use the code from @Ermish, isFaceIdSupported() will return false if there are no enrolled faces on the device. As per my latest tests shows on iOS SDK 11.1, just call the laContext.canEvaluatePolicy function and do not care about the result, then check the content of laContext.biometryType.

If there are no enrolled faces, the canEvaluatePolicy will fail, but the device supports Face ID.

Upvotes: 4

ermish
ermish

Reputation: 1270

I just figured out the problem! You have to call canEvaluatePolicy for biometryType to be properly set.

Example:

func isFaceIdSupported() -> Bool {
    if #available(iOS 11.0, *){
        if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
            return context.biometryType == LABiometryType.typeFaceID
        }
    }

    return false
}

As per the Apple docs for biometryType:

"This property is only set when canEvaluatePolicy(_:error:) succeeds for a biometric policy. The default value is none."

Upvotes: 37

Related Questions