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?
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:
This code builds without warnings on Xcode
9.2
-9.4
(see comments for9.1
):Here is one more way via the property (for example, on your access instance).
As I am a big fan of extension. I phrase this answer a little differently. Essense is the same. This is a drop-in extension.
Use like this:
Here is my "helper class", it includes passcode also
With Xcode 9, Look at LocalAuthentication -> LAContext -> LABiometryType.
LABiometryType is a enum with values as in attached image
You can check which authentication type supported by device between Touch ID and FaceID or none.
Edit:
Apple have updated values for this enum LABiometryType. none is deprecated now.