Swifit指纹识别小Demo
来源:互联网 发布:逍遥模拟器连不上网络 编辑:程序博客网 时间:2024/05/17 01:59
废话不说直接上代码
import UIKitimport LocalAuthenticationclass FingerprintVerifyManager { //单例实现 static let instance = FingerprintVerifyManager() private init(){} //验证完的闭包回调 typealias TouchIdVerify = (isSuccess:Bool, error:NSError?) ->() //调用指纹验证 func touchIdWithHand(identtyVerify:TouchIdVerify) { let version = UIDevice.currentDevice().systemVersion let result = version.compare("8.0.0") assert(result == NSComparisonResult.OrderedDescending, "IOS8.0以上可使用") let context = LAContext() let resultMsg = "验证指纹密码" //设备验证 let (deviceVerify, error) = checkIsOpenFingerprintVerify() if deviceVerify { context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: resultMsg, reply: { (isSuccess, error) -> Void in NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in identtyVerify(isSuccess: isSuccess, error: error) }) }) }else { print("失败\(error!.code)") deviceVerifyWithError(error) } } //验证出现错误 func deviceVerifyWithError(error:NSError!) { switch error!.code { case Int(kLAErrorTouchIDNotEnrolled): print("\(kLAErrorTouchIDNotEnrolled)") print("设备支持,但用户没有设置") break; case Int(kLAErrorPasscodeNotSet): print("\(kLAErrorPasscodeNotSet)") print("设备支持,但是被禁用") break; default: print("设备不支持") break; } } //设备是否打开/支持指纹验证 func checkIsOpenFingerprintVerify() -> (isopen:Bool, error:NSError?) { let context = LAContext() var error:NSError? let isOpen = context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error) return (isOpen, error) }}
调用
@IBAction func fingerprintVerify(sender: AnyObject) { let finerVerify = FingerprintVerifyManager.instance finerVerify.touchIdWithHand { (isSuccess, error) -> () in print("success:\(isSuccess), error:\(error?.code)") } }
0 0
- Swifit指纹识别小Demo
- 指纹识别Demo 源代码下载
- Android指纹识别demo程序
- 安卓指纹识别demo
- 安卓指纹识别demo
- android 6.0 指纹识别调用 Demo
- Android 指纹识别App开发demo
- Android 6.0指纹识别App开发demo
- Android 6.0指纹识别App开发demo
- Android 6.0指纹识别App开发demo
- Android 6.0指纹识别App开发demo
- Android 6.0指纹识别App开发Demo
- 指纹识别
- 指纹识别
- 指纹识别
- 指纹识别
- 指纹识别
- 指纹识别
- Vim快捷键简介
- Linux环境下段错误的产生原因及调试方法小结
- 异常抛出类
- 欢迎使用CSDN-markdown编辑器
- iOS 代理传值
- Swifit指纹识别小Demo
- js中使用EL表达式
- 剑指offer之面试题9:斐波那契数列
- boost的配置解析库
- EEPROM-24LC512 family
- JSON处理类
- JDK 1.7 1.8 新特性
- QML中ScrollView的自动滚动
- maven