npm i --save @entreek/nativescript-fingerprint-auth
- 版本:8.1.2
- GitHub: https://github.com/NativeScript/plugins
- NPM: https://npmjs.net.cn/package/%40entreek%2Fnativescript-fingerprint-auth
- 下载
- 昨天: 0
- 上周: 0
- 上个月: 0
@nativescript/fingerprint-auth
ns plugin add @nativescript/fingerprint-auth
然后打开 App_Resources/Android/app.gradle
并查找 minSdkVersion
。如果它设置为小于 23 的版本,请将此 overrideLibrary
行添加到 App_Resources/Android/src/main/AndroidManifest.xml
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"
tools:overrideLibrary="com.jesusm.kfingerprintmanager"/>
API
想要比这些原始代码示例更好的指南?阅读 Nic Raboy 关于此插件的博客文章。
可用
JavaScript
var fingerprintAuthPlugin = require('@nativescript/fingerprint-auth');
var fingerprintAuth = new fingerprintAuthPlugin.FingerprintAuth();
fingerprintAuth.available().then(function (avail) {
console.log('Available? ' + avail);
});
TypeScript
import { FingerprintAuth, BiometricIDAvailableResult } from "@nativescript/fingerprint-auth";
class MyClass {
private fingerprintAuth: FingerprintAuth;
constructor() {
this.fingerprintAuth = new FingerprintAuth();
}
this.fingerprintAuth.available().then((result: BiometricIDAvailableResult) => {
console.log(`Biometric ID available? ${result.any}`);
console.log(`Touch? ${result.touch}`);
console.log(`Face? ${result.face}`);
});
}
verifyFingerprint
请注意,在 iOS 模拟器上,这将只是 resolve()
。
fingerprintAuth
.verifyFingerprint({
title: 'Android title', // optional title (used only on Android)
message: 'Scan yer finger', // optional (used on both platforms) - for FaceID on iOS see the notes about NSFaceIDUsageDescription
})
.then((enteredPassword?: string) => {
if (enteredPassword === undefined) {
console.log('Biometric ID OK');
} else {
// compare enteredPassword to the one the user previously configured for your app (which is not the users system password!)
}
})
.catch((err) => console.log(`Biometric ID NOT OK: ${JSON.stringify(err)}`));
verifyFingerprintWithCustomFallback
(仅限 iOS,在 Android 上回退到 verifyFingerprint
)
您可以在错误回调被调用时显示它,而不是回退到 iOS 的默认密码界面。
fingerprintAuth
.verifyFingerprintWithCustomFallback({
message: 'Scan yer finger', // optional, shown in the fingerprint dialog (default: 'Scan your finger').
fallbackMessage: 'Enter PIN', // optional, the button label when scanning fails (default: 'Enter password').
authenticationValidityDuration: 10, // optional (used on Android, default 5)
})
.then(
() => {
console.log('Fingerprint was OK');
},
(error) => {
// when error.code === -3, the user pressed the button labeled with your fallbackMessage
console.log('Fingerprint NOT OK. Error code: ' + error.code + '. Error message: ' + error.message);
}
);
面部识别(iOS)
iOS 11 添加了对 Face ID 的支持,首次由 iPhone X 支持。开发者需要为 NSFaceIDUsageDescription
提供一个值,否则您的应用程序可能会崩溃。
您可以通过向 app/App_Resources/ios/Info.plist
添加类似的内容来提供此值(使用面部识别的原因):
<key>NSFaceIDUsageDescription</key>
<string>For easy authentication with our app.</string>
Security++(iOS)
自 iOS9 以来,可以检查自上次检查以来注册的指纹列表是否已更改。建议您添加此检查,以便您可以防止对应用程序的黑客攻击。有关更多详细信息,请参阅 这篇文章。
因此,在 available
之后检查指纹,而不是检查指纹。
fingerprintAuth.available().then((avail) => {
if (!avail) {
return;
}
fingerprintAuth.didFingerprintDatabaseChange().then((changed) => {
if (changed) {
// re-auth the user by asking for his credentials before allowing a fingerprint scan again
} else {
// call the fingerprint scanner
}
});
});
变更日志
- 6.2.0 修复了 iOS 上的潜在绕过问题。
- 6.1.0 修复了 Android 上的潜在绕过问题。
- 6.0.3 Android 与其他插件的 Intents 冲突。
- 6.0.2 插件在 iOS 生产构建 / TestFlight 中不正确工作。
- 6.0.1 修复了与 NativeScript 3.4 的兼容性问题。
- 6.0.0 允许在 Android 上自定义 UI。
- 5.0.0 更好的
Face ID
支持。破坏性更改,请参阅available
的 API。 - 4.0.1 与 官方 NativeScript 插件种子 对齐。需要 NativeScript 3.0.0+。感谢,@angeltsvetkov!
- 4.0.0 转换为 TypeScript。更改了
verifyFingerprintWithCustomFallback
的错误响应类型。 - 3.0.0 添加了对 Android 的支持。将
nativescript-touchid
重命名为nativescript-fingerprint-auth
(对于任何不便表示歉意!)。 - 2.1.1 Xcode 8 兼容性 - 需要 NativeScript 2.3.0+。
- 2.1.0 添加了
didFingerprintDatabaseChange
以提高安全性。 - 2.0.0 添加了
verifyFingerprintWithCustomFallback
,verifyFingerprint
现在回退到密码。 - 1.2.0 您现在可以使用内置的密码界面作为回退。
- 1.1.1 添加了 TypeScript 定义。
- 1.1.0 添加了Android平台,该平台将始终为
touchid.available
返回false。
许可证
Apache许可证版本2.0