[英]How to check if device has sensor for authentication with biometrics? (react-native-fingerprint-scanner)
我正在使用這個庫對生物識別傳感器(例如面部 ID 或指紋掃描儀)進行身份驗證,但我想知道如何檢測設備是否有傳感器: react-native-fingerprint-scanner
根據它的文檔,有一個名為.isSensorAvailable()
的 API 但我不明白如果設備中沒有任何可用的傳感器,它會返回什么。
您可以像下面的示例一樣使用.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');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.