Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically check support of 'Face Id' and 'Touch Id'

I've integrated LocalAuthentication for my app security purpose, which has been supporting 'Touch Id' based supporting. But now, apple has recently added 'Face Id' based authentication also.

How can I check, which type of authentication is supported by a device. Touch Id or Face Id?

like image 429
Krunal Avatar asked Oct 23 '17 10:10

Krunal


People also ask

What is the difference between Touch ID and Face ID?

As we said Face ID requires you to have open eyes, while Touch ID only requires a fingerprint. There are good and bad things about this.

Is Face ID biometric authentication?

It is a method of biometric identification that uses that body measures, in this case, face and head, to verify the identity of a person through its facial biometric pattern and data.

Do apps support Face ID?

Any app supporting Touch ID will automatically work with Face ID, according to Apple(Opens in a new window). But you'll have to double-check on an individual basis. The app should tell you either directly or somewhere in its settings if it supports Touch ID or Face ID.

How do I authenticate with Face ID?

On the Login screen, you will have the option to Enable Face ID. If you select the option and confirm the permissions to use this feature, Face ID starts detecting your face. If your face recognition fails, an appropriate message displays.


1 Answers

I've been struggling to get this to work and found that I needed to use a single instance of the LAContext and needed to call the LAContextInstance.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) before getting the biometryType. Here is my final code with support for older iOS versions:

import LocalAuthentication  static func biometricType() -> BiometricType {     let authContext = LAContext()     if #available(iOS 11, *) {         let _ = authContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)         switch(authContext.biometryType) {         case .none:             return .none         case .touchID:             return .touch         case .faceID:             return .face         }     } else {         return authContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) ? .touch : .none     } }  enum BiometricType {     case none     case touch     case face } 
like image 51
leifdan01 Avatar answered Oct 13 '22 07:10

leifdan01