我正在使用react-native-fingerprint-scanner
进行Touch ID
、Face ID
和Passcode
的认证。
Touch ID
可以正常工作,但我该如何检查设备是否支持此功能?
我尝试过使用react-native-touch-id
,但它不支持在安卓上使用Face ID
。
有没有什么方法可以在两个平台(iOS/Android)上都实现此功能?
参考:链接
我正在使用react-native-fingerprint-scanner
进行Touch ID
、Face ID
和Passcode
的认证。
Touch ID
可以正常工作,但我该如何检查设备是否支持此功能?
我尝试过使用react-native-touch-id
,但它不支持在安卓上使用Face ID
。
有没有什么方法可以在两个平台(iOS/Android)上都实现此功能?
参考:链接
react-native-touch-id
也支持FaceId,但已不再积极维护。因此,他们建议使用expo本地身份验证。它适用于所有的react native应用程序,无论是否使用expo。
要使用它,首先您必须安装react-native-unimodules
。请按照以下指南操作:https://docs.expo.io/bare/installing-unimodules/
安装完成后,您可以通过以下方式进行安装:
npm install expo-local-authentication
请将以下代码添加到您的导入中:
import LocalAuthentication from 'expo-local-authentication';
之后,我们就可以使用它了。
async function biometricAuth(){
const compatible = await LocalAuthentication.hasHardwareAsync();
if (compatible) {
const hasRecords = await LocalAuthentication.isEnrolledAsync();
if (hasRecords) {
const result = await LocalAuthentication.authenticateAsync();
return result;
}
}
}
它将自动选择可用的本地身份验证(TouchID、FaceID、数字锁、图案锁等),并对用户进行身份验证。
react-native-touch-id
应该同时支持TouchID和FaceID。
iOS允许设备在FaceID/TouchID不可用时回退到使用密码。这并不意味着如果TouchID/FaceID在前几次失败后会恢复到密码,而是如果前者没有注册,则会使用密码。
从文档中可以查看是否支持。
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);
});
expo-local-authentication
。 - johnborgesexpo-local-authentication
的实现指南吗? - Sagarreact-native-touch-id
可以同时适用于 TouchID 和 FaceID。
我已经更新了代码库,现在如果您想在 Face ID 或 Touch ID 失败后使用密码,则会提示输入 PIN(仅适用于 iOS),请查看我的代码库。
https://github.com/avaiyakapil/react-native-touch-id
import TouchID from 'react-native-touch-id';
TouchID.authenticate('Authentication')
.then(success => {
// Success code
})
.catch(error => {
// Failure code
});
输入图像描述 // 使用这个包 import RNBiometrics from "react-native-simple-biometrics"; 这是为了在 Android 和 iOS 上使用指纹和密码
//this code is for checking whether touch id is supported or not
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 enabled
console.log(error);
});
biometryType
只返回true
,那么如何使用pattern/password
? - Sagar