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 ...
随机推荐
- typeid关键字
这么看下去太要命了,有太多东西要学了... 而且视频看起来的确费神,费脑,费耳朵. 所以决定由视频驱动转向代码驱动.主攻vs,c++然后先把界面东西做出来,然后在想后面的东西. 所以今天 [先上来看了 ...
- svn服务器的搭建
subversion是优秀的版本管理工具,下面简单介绍svn服务器和客户端的下载.安装.搭建以及使用 一:下载svn服务器和客户端 1:下载地址服务器下载地址:http://subversion.ap ...
- BIO与NIO、AIO的区别
IO的方式通常分为几种,同步阻塞的BIO.同步非阻塞的NIO.异步非阻塞的AIO. 一.BIO 在JDK1.4出来之前,我们建立网络连接的时候采用BIO模式,需要先在服务端启动一个Serve ...
- WinForm控件小知识
1.DataGridView控件显示自定义表 //造个数据表 DataTable dt = new DataTable(); dt.Columns.Add("DEcode", Sy ...
- java面板
import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JLab ...
- 利用html模板生成Word文件(服务器端不需要安装Word)
利用html模板生成Word文件(服务器端不需要安装Word) 由于管理的原因,不能在服务器上安装Office相关组件,所以只能采用客户端读取Html模板,后台对模板中标记的字段数据替换并返回给客户端 ...
- Response.Redirect("");Server.Transfer("")跳转页面的区别
Response.Redirect("") Server.Transfer("") 转向其他站点 能 不能(只能站内转向) 是否可带QueryString参 ...
- tomcat 6 不支持jsf2.2,仅支持jsf2.0及以下版本
tomcat 6 不支持jsf2.2,仅支持jsf2.0及以下版本 安装tomcat8即可.
- for循环例题
1· 一对幼兔一个月后长成小兔(每对兔子默认一公一母),再过一个月长成成兔并且生下一对小兔,以此类推,两年后有多少对兔子? Console.Write("输入年:"); ...
- 第十一篇、HTML5隐藏播放器播放背景音乐
html5添加网页背景音乐 一个客户要求给网站添加一个背景音乐,我用的是html5添加网页背景音乐的代码,在此记录一下以后有用. html5方法一:<audio autoplay=" ...