CoreBluetooth - TouchID应用
支持系统和机型:
iOS系统的指纹识别功能最低支持的机型为iPhone 5s,最低支持系统为iOS 8,
虽然安装iOS 7系统的5s机型可以使用系统提供的指纹解锁功能,但由于API并未开放,所以理论上第三方软件不可使用。
依赖框架
LocalAuthentication.framework
#import <LocalAuthentication/LocalAuthentication.h>
注意事项
做iOS 8以下版本适配时,务必进行API验证,避免调用相关API引起崩溃。
if(iOS8){xxx} // 系统版本验证
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
使用类
LAContext 指纹验证操作对象
操作流程
- 判断系统版本,iOS 8及以上版本执行-(void)authenticateUser方法,
- 方法自动判断设备是否支持和开启Touch ID。
代码示例
#import "ViewController.h"
#import "MBProgressHUD+MJ.h"
#import <LocalAuthentication/LocalAuthentication.h> #define iOS8 ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0) @interface ViewController ()
- (IBAction)clickMethod:(id)sender; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (IBAction)clickMethod:(id)sender { if (!iOS8) { // iOS8以后支持 touchID
// HUD 提示
[MBProgressHUD showError:@"当前系统不支持touchID"];
return;
} // 调用touchID
[self touchIDShow]; } - (void)touchIDShow
{
// 创建指纹校验对象
LAContext *context = [[LAContext alloc] init]; NSError *error1 = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error1]) {
// 弹出验证
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"touchID error" reply:^(BOOL success, NSError * _Nullable error) { if (success) { // 验证成功
NSLog(@"success");
}else{
switch (error.code) {
case LAErrorSystemCancel:
{
NSLog(@"Authentication was cancelled by the system");
//切换到其他APP,系统取消验证Touch ID
break;
}
case LAErrorUserCancel:
{
NSLog(@"Authentication was cancelled by the user");
//用户取消验证Touch ID
break;
}
case LAErrorUserFallback:
{
NSLog(@"User selected to enter custom password");
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//用户选择输入密码,切换主线程处理
}];
break;
}
default:
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//其他情况,切换主线程处理
}];
break;
}
}
NSLog(@"\n%s\n ---line=%d\n -- error=%@\n", __FUNCTION__, __LINE__, error.localizedDescription);
}
}]; }else{
switch (error1.code) {
case LAErrorTouchIDNotEnrolled:
NSLog(@"LAErrorTouchIDNotEnrolled");
break; case LAErrorPasscodeNotSet:
NSLog(@"LAErrorPasscodeNotSet"); // 此处触发showPasscodeResetAlert方法
break; default:
NSLog(@"Touch ID is unaviliable");
break;
}
}
/*
typedef NS_ENUM(NSInteger, LAError)
{
//授权失败
LAErrorAuthenticationFailed = kLAErrorAuthenticationFailed, //用户取消Touch ID授权
LAErrorUserCancel = kLAErrorUserCancel, //用户选择输入密码
LAErrorUserFallback = kLAErrorUserFallback, //系统取消授权(例如其他APP切入)
LAErrorSystemCancel = kLAErrorSystemCancel, //系统未设置密码
LAErrorPasscodeNotSet = kLAErrorPasscodeNotSet, //设备Touch ID不可用,例如未打开
LAErrorTouchIDNotAvailable = kLAErrorTouchIDNotAvailable, //设备Touch ID不可用,用户未录入
LAErrorTouchIDNotEnrolled = kLAErrorTouchIDNotEnrolled,
} NS_ENUM_AVAILABLE(10_10, 8_0); */ [self dealWithError:error1];
} - (void)dealWithError:(NSError *)error
{
if (error) {
NSLog(@"error = %@", error.localizedDescription);
}
}
@end
CoreBluetooth - TouchID应用的更多相关文章
- iOS蓝牙开发CoreBluetooth快速入门
在iOS开发中,实现蓝牙通信有两种方式,一种是使用传统的GameKit.framework,另一种就是使用在iOS 5中加入的CoreBluetooth.framework. 利用CoreBlueto ...
- CoreBluetooth——IOS蓝牙4.0使用心得
原文链接:http://m.blog.csdn.net/article/details?plg_nld=1&id=51014318&plg_auth=1&plg_uin=1&a ...
- [iOS 基于CoreBluetooth的蓝牙4.0通讯]
一.首先大致介绍下蓝牙4.0的模式,中心和周边: 一般情况下,iPhone作为中心,接收来自周边传感器(比如手环等)采集的数据. 二.那整一个数据通讯的协议是怎样的呢? 为什么要一层层搞这么复杂呢?据 ...
- iOS - (个人隐私钱包调用系统本机TouchID指纹锁验证)
// // ViewController.m // TouchID指纹验证 // // Created by apple on 16/9/18. // Copyright © 2016年 ap ...
- ios CoreBluetooth 警告 is being dealloc'ed while pending connection
ios CoreBluetooth 警告 is being dealloc'ed while pending connection CoreBluetooth[WARNING] <CBPerip ...
- 蓝牙 CoreBluetooth
baseK(相关基础知识)蓝牙常见名称和缩写 BLE:(Bluetooth low energy)蓝牙4.0设备因为低耗电,也叫BLEperipheral,central:外设和中心设备,发起链接的是 ...
- CoreBluetooth - 中心模式
BLE中心模式流程-coding BLE中心模式流程 - 1.建立中心角色 - 2.扫描外设(Discover Peripheral) - 3.连接外设(Connect Peripheral) - 4 ...
- CoreBluetooth
Core Bluetooth的基本常识 每个蓝牙4.0设备都是通过服务(Service)和特征(Characteristic)来展示自己的 一个设备必然包含一个或多个服务,每个服务下面又包含若干个特征 ...
- iOS CoreBluetooth 教程
去App Store搜索并下载“LightBlue”这个App,对调试你的app和理解Core Bluetooth会很有帮助. ================================ Cor ...
随机推荐
- Java基础知识强化之IO流笔记64:合并流SequenceInputStream
1. SequenceInputStream合并流的概述: SequenceInputStream类可以将多个输入流串联在一起,合并为一个输入流,因此,该流也被称为合并流. 2. Sequence ...
- 第二次作业第3题_JH
3.完成小组的“四则运算”项目的需求文档(使用Markdown写文档),尝试同组成员在各自PC上修改同一文档后,如何使用Git命令完成GitHub上的文档的更新,而不产生冲突.并验证GitHub上的文 ...
- C语言结构体的引入
#include <stdio.h> struct student{ int ID; ]; int age; }; int main(){ //赋值: , }; ,.name=}; , , ...
- INSTALLING QUARTUS II V.13.1 64 BIT ON RHEL/CENTOS 6 64 BIT
http://www.digitalsolutionslab.com/installing-quartus-ii-v-13-1-64-bit-on-rhelcentos-6-64-bit/ I hav ...
- scala学习笔记:match表达式
写了一个超级长的表达式,估计不是最简洁的: scala> def foo(ch:Any)=ch match { case true=>"male";case false ...
- 错误源:WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).
Server Error in '/' Application. WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping ...
- GetDeviceCaps() 参数
GetDeviceCaps 检测设备指定信息 参数: #define DRIVERVERSION 0 /* 设备驱动版本 */ #define TECHNOLOGY 2 /* Device class ...
- ###《Machine Learning in Action》 - KNN
初学Python:理解机器学习. 算法是需要实现的,纸上得来终觉浅. // @author: gr // @date: 2015-01-16 // @email: forgerui@gmail.com ...
- someExperience
// 面试题1 var name = 'World'; (function () { if (typeof name==='undefined') { var name = 'jack'; conso ...
- 关于css中的align-content属性详解
align-content 作用: 会设置自由盒内部各个项目在垂直方向排列方式. 条件:必须对父元素设置自由盒属性display:flex;,并且设置排列方式为横向排列flex-direction:r ...