如何将指纹(Touch ID)添加到React Native应用程序中



我一直无法找到使用React Native的Touch ID解决方案。我只能使用设备中注册的手指登录该应用程序,但我如何才能真正注册一个新手指,仅用于该应用程序的身份验证?

毫无疑问,在React Native库背后,有Android/iOS Native代码。在这两种情况下,给定的设备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');
});

仅此而已。。。享受你的编码。。。

最新更新