How To Check Support Of Touch Id, Face Id ,password And Pattern Lock In React-native
Solution 1:
react-native-touch-id
supports FaceId too. But, is not actively maintained anymore. So, they recommend to use expo local authentication. It works in all react native applications regardless of expo or not.
To use this, first you have to install react-native-unimodules
. follow this guide https://docs.expo.io/bare/installing-unimodules/
Once it is installed you can install it by
npm install expo-local-authentication
add following line to your import
import LocalAuthentication from 'expo-local-authentication';
After that, we can use it.
asyncfunctionbiometricAuth(){
const compatible = awaitLocalAuthentication.hasHardwareAsync();
if (compatible) {
const hasRecords = awaitLocalAuthentication.isEnrolledAsync();
if (hasRecords) {
const result = awaitLocalAuthentication.authenticateAsync();
return result;
}
}
}
It will automatically choose between available local authentication (TouchID, FaceID, Number lock, Pattern lock etc) and authenticate the user.
Solution 2:
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.
You can check to see if its supported first.
const optionalConfigObject = {
fallbackLabel: 'Show Passcode',
passcodeFallback: true,
}
TouchID.isSupported(optionalConfigObject)
.then(biometryType => {
// Success codeif (biometryType === 'FaceID') {
console.log('FaceID is supported.');
} else {
console.log('TouchID is supported.');
}
})
.catch(error => {
// Failure codeconsole.log(error);
});
Solution 3:
//this code is for checking whether touch id is supported or notTouchID.isSupported()
.then(biometryType => {
// Success codeif (biometryType === 'FaceID') {
console.log('FaceID is supported.');
} elseif (biometryType === 'TouchID'){
console.log('TouchID is supported.');
} elseif (biometryType === true) {
// Touch ID is supported on Android
}
})
.catch(error => {
// Failure code if the user's device does not have touchID or faceID enabledconsole.log(error);
});
Post a Comment for "How To Check Support Of Touch Id, Face Id ,password And Pattern Lock In React-native"