uniapp APP端使用指紋

使用插件指紋模板:json

https://ext.dcloud.net.cn/plugin?id=358this

Fingerprint模塊管理指紋識別spa

要使用指紋識別功能須要具有條件:.net

  • 確認當前設備環境是否支持指紋識別,
  • 當前設備是否設置密碼鎖屏,
  • 當前設備是否已經錄入指紋。

(Android平臺6.0及以上系統支持,只識別標準Android的指紋API,僅適配Google官方指紋識別的標準接口的設備)插件

以上條件都要知足才能夠使用識別功能,識別功能,指的是與手機中已錄入的指紋進行比對檢測,也就是說,只要與手機中錄入任意指紋比對成功,即可進入成功回調。code

首先須要獲取獲得權限:blog

在 manifest.json文件中配置接口

由於目前市場上仍是有不少設備不支持指紋,因此要先使用 plus.fingerprint.isSupport()  方法判斷(如下三個方法均返回值爲Boolean類型)get

// #ifdef APP-PLUS
if (!plus.fingerprint.isSupport()) { plus.nativeUI.toast('此設備不支持指紋識別'); console.log('此設備不支持指紋識別') } // #endif

再使用   plus.fingerprint.isKeyguardSecure()  判斷是否開啓密碼鎖屏it

// #ifdef APP-PLUS
if (!plus.fingerprint.isKeyguardSecure()) { plus.nativeUI.toast('此設備未設置密碼鎖屏'); console.log('此設備未設置密碼鎖屏') } // #endif

再而後使用   plus.fingerprint.isEnrolledFingerprints()  判斷是否錄入指紋

// #ifdef APP-PLUS
if (!plus.fingerprint.isEnrolledFingerprints()) { plus.nativeUI.toast('此設備未錄入指紋'); console.log('此設備未錄入指紋') } // #endif

因項目須要,這裏我將指紋識別封裝爲一個方法

fingerprint: function() { // #ifdef APP-PLUS
 plus.fingerprint.authenticate(function() { console.log('匹配成功'); }, function(e) { switch (e.code) { case e.AUTHENTICATE_MISMATCH: plus.nativeUI.toast('指紋匹配失敗,請從新輸入'); break; case e.AUTHENTICATE_OVERLIMIT: plus.nativeUI.closeWaiting(); //兼容Android平臺關閉等待框
                plus.nativeUI.toast('指紋識別失敗次數超出限制,請使用其它方式進行認證'); break; case e.CANCEL: plus.nativeUI.toast('已取消識別'); break; default: plus.nativeUI.closeWaiting(); //兼容Android平臺關閉等待框
                plus.nativeUI.toast('指紋識別失敗,請重試'); break; } }); // #endif
},

注:回調裏this指向發生改變,可在回調裏使用其餘方法

相關文章
相關標籤/搜索