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 ...
随机推荐
- Cstring到string
要利用mfc,然后接受一个图片. imread只能读const string& filename 的东西. imread 原型: CV_EXPORTS_W Mat imread( ); 它的参 ...
- mysql数据库常用语句3
一:查询指定数据库中所有的表名 数据库名:test select table_name from information_schema.tables where table_schema='test' ...
- 纯CSS实现三列布局(两边固定,中间自适应)
看了一些网上的案例,感觉较繁杂,于是,自己整理了一篇来说明这个东西. 也是给我自己复习吧,以前有人问道,我还没答上来呢.== 看代码: html: <div class="top&qu ...
- createjs 使用记录
createjs由几个库组成: l,easeljs,这个是核心,包括了显示列表.事件机制: 2,preloadjs,用于预加载图片等: 3,tweenjs,用于控制元件的缓动: 4,soundjs,用 ...
- Entity Framework 学习整理(分播客整理)
MSDN: http://msdn.microsoft.com/en-us/data/aa937723 台湾博客: http://www.dotblogs.com.tw/yc421206/ http: ...
- oracle的sid
SID是一个数据库的唯一标识符!是你在建立一个数据库时系统自动赋予的一个初始ID,虽说他和数据库名(DB_NAME)都是一个数据库的唯一标识符,但是在作用上就有不小区别.SID主要用于在一些DBA操作 ...
- awk与cut在以空格为分割域时的区别
awk默认以空格为分割域,比如我想获得某进程pid:[root@SHCTC-GAME12-44 ~]# ps -ef|grep "sshd -f"|grep -v greproot ...
- ios - cordova(phoneGap)
安装教程 下载 node.js. http://nodejs.org/ 下载后,直接安装就可以了. 安装 Cordova工具, $ sudo npm install -g cordova 创建APP: ...
- 11_Jaxws常用注解
[不使用注解] 默认namespace是服务类包名的倒序 默认portType是服务类的类名 ............... 注解的所起的作用: Jaxws提供的注解可以对WebService的接口规 ...
- MSBuild could not create or connect to a task host with runtime "CLR2" and architecture "x86".
vs2010 and vs2012 are installed on target machine. Build c# project using vs2010, following error oc ...