如何在React-Native中检查Touch ID、Face ID、密码和图案锁的支持。

12

我正在使用react-native-fingerprint-scanner进行Touch IDFace IDPasscode的认证。

Touch ID可以正常工作,但我该如何检查设备是否支持此功能?

我尝试过使用react-native-touch-id,但它不支持在安卓上使用Face ID

有没有什么方法可以在两个平台(iOS/Android)上都实现此功能?

参考:链接

enter image description here

enter image description here


如何在React Native中检查任何库? - Sagar
1
对我来说,biometryType 只返回 true,那么如何使用 pattern/password - Sagar
'biometryType'的值始终为true,而不是字符串吗? - hong developer
在我的设备上,我已经设置了所有三个模式,它返回“true”。 - Sagar
你已经为 Face ID 修复了吗? - Kailash
显示剩余2条评论
5个回答

3

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设计的。Expo团队使其支持RN。请按照上述步骤操作。 - Haseeb A
"应该就在这里:import * as LocalAuthentication from 'expo-local-authentication';" - Peanut Shi
这个解决方案不适用于仅支持面部识别解锁的安卓设备。你知道有什么解决方案吗?我在这里提供了精确的问题:https://stackoverflow.com/questions/73391435/face-id-biometry-face-recognition-unlock-on-android-devices-in-react-native - Piotr Witkoś

1

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);
  });

如果指纹扫描没有完成,您是否已经为密码进行了设置? - Sagar
据我理解,这不是密码回退的工作原理。请查看我的更新答案。 - johnborges
react-native-touch-id是一个已弃用的插件,今天我可以使用哪个插件? - shogitai
它看起来并没有被弃用,只是没有得到积极的维护。一个替代方案是 expo-local-authentication - johnborges
@johnborges,你有这个expo-local-authentication的实现指南吗? - Sagar
如果Touch ID或Face ID无法使用,您可以使用设备密码。您可以在此处(https://github.com/avaiyakapil/react-native-touch-id)找到我的指南和代码示例。 - avaiyakapil

0

react-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
            });

0

输入图像描述 // 使用这个包 import RNBiometrics from "react-native-simple-biometrics"; 这是为了在 Android 和 iOS 上使用指纹和密码


请考虑直接在回答中分享代码,而不是以截图的形式呈现。 - Pranjal Gore

-2
//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);
          });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接