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 ...
随机推荐
- CSS3——选项卡切换
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 数据结构及算法分析(0)——引论
引论提到算法递归的概念,递归在很多算法中都会出现.所谓递归,当一个函数用它自己来定义的时候就称为递归. 递归调用有两大要素: 基准情况. 递归调用. 并非所有的数学递归函数 ...
- ORM之PetaPoco入门(一)--Petapoco简介
1. ORM概括 1.1. ORM简介 ORM 对象-关系映射(Object/Relation Mapping,简称ORM),是随着面向对象的软件开发方法发展而产生的.面向对象的开发方法是当今企业级应 ...
- WebSocket原理及与http1.0/1.1 long poll和 ajax轮询的区别【转自知乎】
一.WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环连接的不算)首先HTTP有1.1和1.0之说,也就是所谓的ke ...
- 关于Eclipse插件开发-----加入首选项(preferencePages)
选择主菜单"窗口---->首选项"命令打开"首选项"窗口.此窗口是Eclipse设置项的集中营, 修改plugin.xml文件,设置首选项的扩展点: pl ...
- SqlBulkCopy 数据批量操作使用的类
private void SqlBulkCopyByDataTable(string connectionString,string TableName,DataTable dt) { using ( ...
- asp.net中常用的几种身份验证方式
转载:http://www.cnblogs.com/dinglang/archive/2012/06/03/2532664.html 前言 在B/S系统开发中,经常需要使用"身份验证&q ...
- HW-找7(测试ok满分注意小于等于30000的条件)
输出7有关数字的个数,包括7的倍数,还有包含7的数字(如17,27,37...70,71,72,73...)的个数 知识点 循环 运行时间限制 0M 内存限制 0 输入 一个正整数N.(N不大于300 ...
- Mysql 的变量
变量 MySQL是一门编程语言.所以存在变量.流程控制.函数.存储过程.触发器 MySQL分系统变量,与自定义变量 MySQL的某些功能是通过系统变量来实现的.例如:autocommit 查看系统变量 ...
- 使用C++11安全的在线程中控制UI
本篇文章由:http://www.sollyu.com/using-the-c11-secure-online-process-control-ui/ 说明 首先这里使用的是 Visual Studi ...