简体   繁体   English

如何检查设备是否具有用于生物识别身份验证的传感器? (react-native-fingerprint-scanner)

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

I am using this library to authenticate with biometrics sensor such as face ID or fingerprint scanner but I would like to know how to detect whether the device has a sensor or not: react-native-fingerprint-scanner我正在使用这个库对生物识别传感器(例如面部 ID 或指纹扫描仪)进行身份验证,但我想知道如何检测设备是否有传感器: react-native-fingerprint-scanner

according to it's documentation there is an API called .isSensorAvailable() but I dont understand what does it return in case there isn't any available sensor in the device.根据它的文档,有一个名为.isSensorAvailable()的 API 但我不明白如果设备中没有任何可用的传感器,它会返回什么。

You can use the .isSensorAvailable() API like this example below.您可以像下面的示例一样使用.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))

import ReactNativeBiometrics from 'react-native-biometrics';从“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');
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM