RN指纹识别库 – react-native-fingerprint-identify

weixin_38071213 2019-09-12 11:54:43
react-native-fingerprint-identify eact-native 指纹识别库,不过只支持安卓的说。 这是一个可扩展的兼容的 指纹识别库 , 也能够联合  Samsung 和 MeiZu 官方指纹识别库。 Demo Getting started $ npm install react-native-fingerprint-identify –save Most automatic installation $ react-native link react-native-fingerprint-identify Make sure the following lines inandroid/app/build.gradle: android { compileSdkVersion 25 buildToolsVersion "25.0.2" ... defaultConfig { targetSdkVersion 25 Manual Installation Open upandroid/app/src/main/java/[…]/MainApplication.java Addimport com.fingerprint.identify.RNFingerprintIdentifyPackage; to the imports at the top of the file Addnew RNFingerprintIdentifyPackage() to the list returned by thegetPackages()method Append the following lines toandroid/settings.gradle: include ':react-native-fingerprint-identify' project(':react-native-fingerprint-identify').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fingerprint-identify/android') Make sure the following lines inandroid/app/build.gradle: android { compileSdkVersion 25 buildToolsVersion "25.0.2" ... defaultConfig { targetSdkVersion 25 Insert the following lines inside the dependencies block inandroid/app/build.gradle in dependencies block compile project(':react-native-fingerprint-identify') Example Please clone repo and look on the example project to get more details import FingerprintIdentify from 'react-native-fingerprint-identify'; import { Platform } from 'react-native' // Make sure you run in Android Platform condition scanFingerprint = async () => { if (Platform.OS === 'android') { try { const initFingerPrintIdentify = await FingerprintIdentify.initFingerPrintIdentify() const isSensorAvailable = await FingerprintIdentify.isSensorAvailable() if (initFingerPrintIdentify && isSensorAvailable) { await FingerprintIdentify.startIdentify((status) => { console.log(status) }) } } catch (error) { console.log(error) return } } } Usage Easy custom error message with error codes. Errors on startIdentify() function: ERROR_NOT_AVAILABLE ERROR_NOT_MATCH ERROR_NOT_MATCH_AND_CHANCES_LEFT:(AvailableTimes) Errors on isSensorAvailable() function: ERROR_HARDWARE: The device does not support fingerprint scanning. ERROR_ENROLLED: No fingerprints registered. ERROR_PERMISSION: App has no permission. ERROR_INITIALIZED: The FingerPrintIdentify can not initialize Init FingerprintIdentify before request scan. FingerprintIdentify.initFingerPrintIdentify() Promise returns true if success and string error in other cases (including case when you have sensor, but not enabled it in your phone’s settings) FingerprintIdentify.isSensorAvailable() Starting scan finger print and get the result in the callback function, returns true if success and string error in other cases. FingerprintIdentify.startIdentify((val) => console.log(val)) Removing event listener (fingerprint identity status) – prevent crash App after authentication, usually put in componentWillUnmount() FingerprintIdentify.dismiss() Removing event listener to scan fingerprint and also cancel identify FingerprintIdentify.cancelIdentify()
...全文
176 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧