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
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.
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)
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
How to Convert Text to Image on iOS
Custom Cell Reorder Behavior in Collectionview
Uinavigationcontroller Without Navigation Bar
How to Solve "Error Running Pod Install" in Flutter on MAC
Nspredicate to Test for Null, and Blank Strings
How to Get the Hour of the Day with Swift
Xcode Won't Let to Build for Device After Denying Codesign to Access Keychain
How to Convert Including Timezone Date in Swift
Cagradientlayer Diagonal Gradient
How to Change the Uisearchbar Search Text Color
How to Add Constraint Between a View and the Top Layout Guide in a Xib File
How to Turn Flashlight on and Off in Swift
Uiscrollview Adjusts Contentoffset When Contentsize Changes
Facebook Share Content Only Shares Url in iOS 9
How to Recycle Uitableviewcell Objects Created from a Xib
Avaudiosession Setcategory Swift 4.2 iOS 12 - Play Sound on Silent