【问题标题】:How to check if device has sensor for authentication with biometrics? (react-native-fingerprint-scanner)如何检查设备是否具有用于生物识别身份验证的传感器? (react-native-fingerprint-scanner)
【发布时间】:2020-07-31 16:29:31
【问题描述】:

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

根据它的文档,有一个名为 .isSensorAvailable() 的 API,但我不明白如果设备中没有任何可用的传感器,它会返回什么。

【问题讨论】:

    标签: react-native fingerprint biometrics touch-id face-id


    【解决方案1】:

    从“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');
      }
    });
    

    【讨论】:

      【解决方案2】:

      您可以使用.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))
      

      【讨论】:

      • 太好了@dfgd
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 2018-12-16
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      相关资源
      最近更新 更多