【问题标题】:How to check support of Touch ID, Face Id ,Password and pattern lock in React-Native如何在 React-Native 中检查对 Touch ID、Face ID、密码和模式锁定的支持
【发布时间】:2020-02-01 17:57:09
【问题描述】:

我已经实现了一个react-native-fingerprint-scanner,它适用于Touch Id

现在我想为两个平台的Touch ID、Face ID、Passcode添加身份验证

有什么方法可以检查您的设备是否支持。另外,我尝试过使用react-native-touch-id,但它不适用于android 上的Face Id

有什么方法可以在两个平台(iOS/Android)上实现这一点吗?

参考:Link

【问题讨论】:

  • 可以查看设备是否被某个模块支持。有什么问题?
  • 如何检查 react-native 的任何库?
  • Johnborges 已经写了答案。
  • 对我来说biometryType 只返回true 以及如何去pattern/password
  • 'biometryType' 的值是否始终为真,而不是字符串?

标签: react-native touch-id face-id passcode android-biometric


【解决方案1】:

react-native-touch-id 也支持 FaceId。但是,不再积极维护。因此,他们建议使用 expo 本地身份验证。它适用于所有 React Native 应用程序,无论是否展示。

要使用它,首先你必须安装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、数字锁、图案锁等)之间进行选择并对用户进行身份验证。

【讨论】:

  • 是的,它用于反应原生。 Expo团队使其支持RN。请按照上述步骤操作。
  • "import * as LocalAuthentication from 'expo-local-authentication';" 应该就在这里。
【解决方案2】:

react-native-touch-id 应该适用于 TouchID 和 FaceID。

如果 faceid/touch 不可用,iOS 允许设备回退到使用密码。这并不意味着如果 touchid/faceid 前几次失败,它将恢复为密码,而是如果前者未注册,则它将使用密码。

from the docs

您可以先查看是否支持。

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

【讨论】:

  • 如果手指扫描未完成,您是否已完成密码验证
  • 据我了解,这不是密码回退的工作方式。请参阅我的更新答案。
  • react-native-touch-id 是一个已弃用的插件,我今天可以使用哪个插件?
  • 它看起来并没有被弃用,只是没有得到积极的维护。另一种方法是expo-local-authentication
  • @johnborges 你有这个expo-local-authentication 的实施指南吗?
【解决方案3】:
//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);
          });

【讨论】:

    猜你喜欢
    • 2018-04-03
    • 1970-01-01
    • 2022-09-29
    • 1970-01-01
    • 2023-01-26
    • 1970-01-01
    • 2019-04-18
    • 2015-01-23
    • 1970-01-01
    相关资源
    最近更新 更多