支持系统和机型:

  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应用的更多相关文章

  1. iOS蓝牙开发CoreBluetooth快速入门

    在iOS开发中,实现蓝牙通信有两种方式,一种是使用传统的GameKit.framework,另一种就是使用在iOS 5中加入的CoreBluetooth.framework. 利用CoreBlueto ...

  2. CoreBluetooth——IOS蓝牙4.0使用心得

    原文链接:http://m.blog.csdn.net/article/details?plg_nld=1&id=51014318&plg_auth=1&plg_uin=1&a ...

  3. [iOS 基于CoreBluetooth的蓝牙4.0通讯]

    一.首先大致介绍下蓝牙4.0的模式,中心和周边: 一般情况下,iPhone作为中心,接收来自周边传感器(比如手环等)采集的数据. 二.那整一个数据通讯的协议是怎样的呢? 为什么要一层层搞这么复杂呢?据 ...

  4. iOS - (个人隐私钱包调用系统本机TouchID指纹锁验证)

    // //  ViewController.m //  TouchID指纹验证 // //  Created by apple on 16/9/18. //  Copyright © 2016年 ap ...

  5. ios CoreBluetooth 警告 is being dealloc'ed while pending connection

    ios CoreBluetooth 警告 is being dealloc'ed while pending connection CoreBluetooth[WARNING] <CBPerip ...

  6. 蓝牙 CoreBluetooth

    baseK(相关基础知识)蓝牙常见名称和缩写 BLE:(Bluetooth low energy)蓝牙4.0设备因为低耗电,也叫BLEperipheral,central:外设和中心设备,发起链接的是 ...

  7. CoreBluetooth - 中心模式

    BLE中心模式流程-coding BLE中心模式流程 - 1.建立中心角色 - 2.扫描外设(Discover Peripheral) - 3.连接外设(Connect Peripheral) - 4 ...

  8. CoreBluetooth

    Core Bluetooth的基本常识 每个蓝牙4.0设备都是通过服务(Service)和特征(Characteristic)来展示自己的 一个设备必然包含一个或多个服务,每个服务下面又包含若干个特征 ...

  9. iOS CoreBluetooth 教程

    去App Store搜索并下载“LightBlue”这个App,对调试你的app和理解Core Bluetooth会很有帮助. ================================ Cor ...

随机推荐

  1. Cadence画封装的步骤

    画封装的步骤 打开 pad designer       through 通孔       single  表贴      在焊盘设置时,soldermask层要比pastmask大0.1毫米     ...

  2. [Search]swf 转mp4,未成功

    Need help to convert SWF to something else.. 知道recordmydesktop 和 xvidcap 两个录像软件. 在尝试了自己的净土 下面的 ADSha ...

  3. 理解Spark的RDD

    RDD是个抽象类,定义了诸如map().reduce()等方法,但实际上继承RDD的派生类一般只要实现两个方法: def getPartitions: Array[Partition] def com ...

  4. RabbitMQ 原文译02--工作队列

    工作队列: 在上一篇文章中我们我们创建程序发送和接受命名队列中的消息,在这篇文章我会创建一个工作队列,用来把耗时的操作分配给多个执行者. 工作队列(任务队列)的主要实现思想是避免马上执行资源密集型的任 ...

  5. 解决div布局中第一个div的margin-top在浏览器中显示无效果问题。

    原味来源:http://www.hicss.net/do-not-tell-me-you-understand-margin/ 垂直外边距合并问题 别被上面这个名词给吓倒了,简单地说,外边距合并指的是 ...

  6. spring.net 和 mybatis.net

    demo是整合现有的spring.net 和 mybatis.net 完成的控制台程序,需要注意的地方:关于Config文件夹中的config文件的属性设定:同时保证Providers.config默 ...

  7. 对比MySQL,什么场景MongoDB更适用

    原文链接: http://page.factj.com/blog/p/4078 MongoDB已经流行了很长一段时间,相对于MySQL,究竟什么场景更需要用MongoDB?下面是一些总结. 更高的写入 ...

  8. HTML Music Entities/音乐符号

    HTML Music Entities Musical symbols Description Character(click) HTML-Entity Code-Decimal Code-Hex Q ...

  9. C++ 遇见的一些函数

    1.位与(&)操作,计算十进制数中的为"1"的位数 int cnt_one(int k) { ; //保存位为"1"的数量 while (k) { k ...

  10. mysql innodb 数据打捞(一)innodb 页面结构特征

    如果文件系统损坏或意外删除了数据库文件,只要磁盘空间没有被覆盖,其实数据都还在磁盘的扇区中,还是可以恢复出来的,有些通用的文件恢复工具好象也可以恢复文件 ,但这里要研究的是在通用文件 恢复工具失效的时 ...