How to Programmatically Check Support of 'Face Id' and 'Touch Id'

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

With Xcode 9, Look at LocalAuthentication -> LAContext -> LABiometryType.

LABiometryType is a enum with values as in attached image

Sample 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.

Sample Image

Extension to check supported Biometric Type with Swift 5:

import LocalAuthentication

extension LAContext {
enum BiometricType: String {
case none
case touchID
case faceID
}

var biometricType: BiometricType {
var error: NSError?

guard self.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
return .none
}

if #available(iOS 11.0, *) {
switch self.biometryType {
case .none:
return .none
case .touchID:
return .touchID
case .faceID:
return .faceID
@unknown default:
#warning("Handle new Biometric type")
}
}

return self.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) ? .touchID : .none
}
}

How to check support of Touch ID, Face Id ,Password and pattern lock in React-Native

react-native-touch-id should work for both TouchID and FaceID.

iOS allows the device to fall back to using the passcode, if faceid/touch is not available. this does not mean that if touchid/faceid fails the first few times it will revert to passcode, rather that if the former are not enrolled, then it will use the passcode.

from the docs

You can check to see if its supported first.

const optionalConfigObject = {
fallbackLabel: 'Show Passcode',
passcodeFallback: true,
}

TouchID.isSupported(optionalConfigObject)
.then(biometryType => {
// Success code
if (biometryType === 'FaceID') {
console.log('FaceID is supported.');
} else {
console.log('TouchID is supported.');
}
})
.catch(error => {
// Failure code
console.log(error);
});

How to check Face id is enabled for my application?]

let context = LAContext()
if ( context.biometryType == .typeFaceID ) {
// Face ID
}
if ( context.biometryType == .typeTouchID) {
// Touch ID
} else {
// Stone Age
}

don't forgot to put versioning condition cuz faceID is only available after ios 11

Determine if an iOS device supports TouchID without setting passcode

In conclusion of the discussion below, for the time being it is not possible to determine whether a device actually supports TouchID or not when the user hasn't set up passcode on their device.

I have reported this TouchID flaw on the Apple bug reporter. Those who want to follow the issue can see it on Open Radar here: http://www.openradar.me/20342024

Thanks @rckoenes for the input :)

EDIT

Turns out that someone has reported a similar issue already (#18364575). Here is Apple's reply regarding the issue:

"Engineering has determined that this issue behaves as intended based on the following information:

If passcode is not set, you will not be able to detect Touch ID presence. Once the passcode is set, canEvaluatePolicy will eventually return LAErrorTouchIDNotAvailable or LAErrorTouchIdNotEnrolled and you will be able to detect Touch ID presence/state.

If users have disabled passcode on phone with Touch ID, they knew that they will not be able to use Touch ID, so the apps don't need to detect Touch ID presence or promote Touch ID based features. "

So..... the final answer from Apple is No. :(

Note: similar StackOverflow question from the person who reported this -> iOS8 check if device has Touch ID
(wonder why I didn't find this question before despite my extensive searching...)

Touch ID vs Face ID code

You don't have to update your code to be Face ID ready if your app already supports Touch ID. (as seen here)
Sample Image
iOS takes care of all the work under the hood.

What you can do however, is to change your strings containing "Touch ID" to "Face ID" if the app is running on a Face ID capable device.

Edit: As noted by MikeMertsock, the LAContext class has a biometryType property to determine whether the device uses Touch ID or Face ID.



Related Topics



Leave a reply



Submit