如何检查设备是否具有用于生物识别认证的传感器? (反应本机指纹扫描仪)

How to check if device has sensor for authentication with biometrics? (react-native-fingerprint-scanner)

我正在使用此库通过生物识别传感器(例如面部 ID 或指纹扫描仪)进行身份验证,但我想知道如何检测设备是否具有传感器:react-native-fingerprint-scanner

根据其文档,有一个名为 .isSensorAvailable() 的 API,但我不明白它的作用 return,以防设备中没有任何可用的传感器。

您可以像下面这个例子一样使用 .isSensorAvailable() API。

import FingerprintScanner from 'react-native-fingerprint-scanner'

    FingerprintScanner
                .isSensorAvailable()
                .then(() => {
                // Call the Fingerprint Scanner Method
                    FingerprintScanner
                        .authenticate({ description: 'Authenticate to access this' })
                        .then(() => {
                            // Method for Authentication
                            onAuthenticate()
                        })
                        // Call error method
                        .catch(error => onAuthenticationFailure(error))

                })
                 //Call the error method
                .catch(error => onAuthenticationFailure(error))

从 'react-native-biometrics' 导入 ReactNativeBiometrics;

ReactNativeBiometrics.isSensorAvailable().then(resultObject => {
  const {available, biometryType} = resultObject;

  if (available && biometryType === ReactNativeBiometrics.TouchID) {
    console.log('TouchID is supported');

  } else if (available && biometryType === ReactNativeBiometrics.FaceID) {
    console.log('FaceID is supported');

  } else if (
    available &&
    biometryType === ReactNativeBiometrics.Biometrics
  ) {
    console.log('Biometrics is supported');
    try{
ReactNativeBiometrics.simplePrompt({
  promptMessage: 'Confirm fingerprint',
})
  .then(resultObject => {
    const {success} = resultObject;

    if (success) {
      console.log('successful biometrics provided');

    } else {
      console.log('user cancelled biometric prompt');
    }
  })
  .catch(() => {
    console.log('biometrics failed');
  });
}
catch(e){
  console.log("Device not Support Fingerprint")
}
  } else {
    console.log('Biometrics not supported');
  }
});