我还没有找到使用 React-Native 的 Touch ID 的解决方案。我只能使用设备中注册的手指登录应用程序,但如何才能实际注册新手指以仅用于通过该应用程序进行身份验证?
当然,React Native 库的背后是 Android/iOS 原生代码。在这两者中,给定的设备 API 允许开发人员使用指纹保存的数据进行身份验证。您无法获取指纹数据并将其保存在您的应用程序或服务器上。欲了解更多信息,您可以查看这篇文章。
所以,由于本机端的限制,
React Native
无法获取指纹数据。
这是不可能的。
//this is for checking suppport of face id and touch id on your device
TouchID.isSupported()
.then(biometryType => {
// Success code
if (biometryType === 'FaceID') {
console.log('FaceID is supported.');
} else if (biometryType === 'TouchID'){
console.log('TouchID is supported.');
} else if (biometryType === true) {
// Touch ID is supported on Android
}
})
.catch(error => {
// Failure code if the user's device does not have touchID or faceID
console.log(error);
});
// this is for applying touch id
TouchID.isSupported()
.then(authenticate)
.catch(error => {
AlertIOS.alert('TouchID not supported');
});
import TouchID from 'react-native-touch-id';
const optionalConfigObject = {
title: 'Authentication Required', // Android
color: 'ffffff', // Android,
fallbackLabel: 'Show Passcode', // iOS (if empty, then label is hidden)
};
TouchID.isSupported()
.then(biometryType => {
// Success code
if (biometryType === 'FaceID') {
console.log('FaceID is supported.');
} else {
console.log('TouchID is supported.');
TouchID.authenticate('Authenticate', optionalConfigObject)
.then(success => {
Alert.alert('Authenticated Successfully');
})
.catch(error => {
Alert.alert('Authentication Failed', error.toString());
});
}
})
.catch(error => {
// Failure code
Alert.alert('No TouchId and FaceId Detected in this device');
});
仅此而已...祝您编码愉快...