#新增 Android 1.android 6.0 指纹解锁
#####需要在build.gradle文件中添加 android-support-v4 的引用 官方文档1 官方文档2
dependencies {
...
compile "com.android.support:support-core-utils:24.2.1"
}
#####各个型号说明 1.华为
通过指纹模块实现app的登录鉴权,可通过android 6.0的公开接口实现指纹的对接。
目前搭载EMUI4.0 (基于android 6.0深度定制的系统)的华为手机均支持android官方对指纹的公开开放接口。
EMUI4.0以下系统的指纹接口属于华为内部私有接口,暂不开放。
2.三星
暂未开发
3.Google Nexus
因为Google Android 6.0(API 23) 以上都支持
4.小米
6.0 以上
5.乐视
暂未开发
6.魅族
暂未开发
7.OPPO
暂未开发
8.联想
暂未开发
##接口 1.isAvailable
#isAvailable
###android
- Description
- Screenshot
- Installation 3. Automatically (CLI / Plugman) 3. Manually
- Usage
- Security++
- License
Scan the fingerprint of your user with the TouchID sensor (iPhone 5S).
- Compatible with Cordova Plugman.
- Minimum iOS version is 8 (error callbacks will be gracefully invoked on lower versions).
- Requires a fingerprint scanner, so an iPhone 5S or newer is required.
Distorted a bit because I created it back when Apple had not yet released the SDK and they're not a fan of developers posting screenshots of unreleased features.
Compatible with Cordova Plugman, compatible with PhoneGap 3.0 CLI, here's how it works with the CLI (backup your project first!):
From npm:
$ cordova plugin add cordova-plugin-touch-id
$ cordova prepare
The latest, from the master repo:
$ cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-touch-id
$ cordova prepare
TouchID.js is brought in automatically. There is no need to change or add anything in your html.
1. Add the following xml to your config.xml
in the root directory of your www
folder:
<feature name="TouchID">
<param name="ios-package" value="TouchID" />
</feature>
You'll need to add the LocalAuthentication.framework
and Security.framework
to your project.
Click your project, Build Phases, Link Binary With Libraries, search for and add the frameworks.
2. Grab a copy of TouchID.js, add it to your project and reference it in index.html
:
<script type="text/javascript" src="js/TouchID.js"></script>
3. Download the source files and copy them to your project.
iOS: Copy the two .h
and two .m
files to platforms/ios/<ProjectName>/Plugins
First you'll want to check whether or not the user has a configured fingerprint scanner. You can use this to show a 'log in with your fingerprint' button next to a username/password login form.
window.plugins.touchid.isAvailable(
function(msg) {alert('ok: ' + msg)}, // success handler: TouchID available
function(msg) {alert('not ok: ' + msg)} // error handler: no TouchID available
);
If the onSuccess handler was called, you can scan the fingerprint.
There are two options: verifyFingerprint
and verifyFingerprintWithCustomPasswordFallback
.
The first method will offer a fallback option called 'enter passcode' which shows the default passcode UI when pressed.
The second method will offer a fallback option called 'enter password' (not passcode) which allows you to provide your own password dialog.
window.plugins.touchid.verifyFingerprint(
'Scan your fingerprint please', // this will be shown in the native scanner popup
function(msg) {alert('ok: ' + msg)}, // success handler: fingerprint accepted
function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);
The errorhandler of the method above can receive an error code of -2
which means the user pressed the 'enter password' fallback.
window.plugins.touchid.verifyFingerprintWithCustomPasswordFallback(
'Scan your fingerprint please', // this will be shown in the native scanner popup
function(msg) {alert('ok: ' + msg)}, // success handler: fingerprint accepted
function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);
This will render a button labelled 'Enter password' in case the fingerprint is not recognized. If you want to provide your own label ('Enter PIN' perhaps), you can use awkwardly named function (added in version 3.1.0):
window.plugins.touchid.verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel(
'Scan your fingerprint please', // this will be shown in the native scanner popup
'Enter PIN', // this will become the 'Enter password' button label
function(msg) {alert('ok: ' + msg)}, // success handler: fingerprint accepted
function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);
You can copy-paste these lines of code for a quick test:
<button onclick="window.plugins.touchid.isAvailable(function(msg) {alert('ok: ' + msg)}, function(msg) {alert('not ok: ' + msg)})">Touch ID available?</button>
<button onclick="window.plugins.touchid.verifyFingerprint('Scan your fingerprint please', function(msg) {alert('ok: ' + msg)}, function(msg) {alert('not ok: ' + JSON.stringify(msg))})">Scan fingerprint</button>
Since iOS9 it's possible to check whether or not the list of enrolled fingerprints changed since the last time you checked it. It's recommended you add this check so you can counter hacker attacks to your app. See this article for more details.
So instead of checking the fingerprint after isAvailable
add another check.
In case didFingerprintDatabaseChange
returns true
you probably want to re-authenticate your user
before accepting valid fingerprints again.
window.plugins.touchid.isAvailable(
function(available) {
if (available) {
window.plugins.touchid.didFingerprintDatabaseChange(
function(changed) {
if (changed) {
// re-auth the user by asking for his credentials before allowing a fingerprint scan again
} else {
// call the fingerprint scanner
}
}
);
}
}
);