iOS开发之指纹解锁
http://blog.csdn.net/hongfengkt/article/details/49868073
前一阵子一直在赶项目进度,没有太多时间写博客,现在终于空闲了,将以前欠下的博客补上来。
在iOS8.0之后,API开放了指纹验证的功能。开放的API虽然只能用来作为验证使用,比较局限,但是对于有类似“手势密码”功能的app来说,已经足够用了。有了这个新api,就可以在app中再多一种高大上的解锁方式了。
指纹验证功能的最低硬件支持为iPhone5s,iPad 6,iPad mini 3这些有touch ID硬件支持的设备,并且操作系统最低为iOS8.0,因为touch ID是在iOS8.0之后才开放的一类api。
下面放代码。
做iOS8.0下版本适配时,务必进行API验证,避免调用相关API引起崩溃。
引入依赖框架:
#import <LocalAuthentication/LocalAuthentication.h>
- 1
- 1
指纹验证的实现
- (void)authenticateUser
{
//初始化上下文对象
LAContext* context = [[LAContext alloc] init];
//错误对象
NSError* error = nil;
NSString* result = @"Authentication is needed to access your notes.";
//首先使用canEvaluatePolicy 判断设备支持状态
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
//支持指纹验证
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {
if (success) {
//验证成功,主线程处理UI
}
else
{
NSLog(@"%@",error.localizedDescription);
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;
}
}
}
}];
}
else
{
//不支持指纹识别,LOG出错误详情
switch (error.code) {
case LAErrorTouchIDNotEnrolled:
{
NSLog(@"TouchID is not enrolled");
break;
}
case LAErrorPasscodeNotSet:
{
NSLog(@"A passcode has not been set");
break;
}
default:
{
NSLog(@"TouchID not available");
break;
}
}
NSLog(@"%@",error.localizedDescription);
[self showPasswordAlert];
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
对几种情况的说明
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);
iOS开发之指纹解锁的更多相关文章
- iOS --- Touch ID指纹解锁
https://www.cnblogs.com/ljmaque/p/TouchID.html 最近在项目中刚好用到了TouchId指纹解锁功能,之前也没有接触过,立马百度看看究竟是要如何使用,发现其实 ...
- ios开发-指纹识别
最近我们使用支付宝怎么软件的时候,发现可以使用指纹了,看起来是否的高大上.当时苹果推出了相关接口,让程序写起来很简单哈. 在iPhone5s的时候,苹果推出了指纹解锁.但是在ios8.0的时候苹果才推 ...
- iOS 指纹解锁 验证TouchID
iOS指纹解锁 1.首先,引入依赖框架 LocalAuthentication.framework #import <LocalAuthentication/LocalAuthenticatio ...
- iOS 指纹解锁
目前常用的App支持指纹解锁的还不是很多,如果在你的项目中用一下是不是显得高大上呢? 废话不说多,干货- 1.在工程中添加LocalAuthentication.framework 2.在需要验证的c ...
- iOS 。开发之指纹识别功能
// 头文件导入 #import <LocalAuthentication/LocalAuthentication.h> //在iPhone5s的时候,苹果推出了指纹解锁.但是在ios8. ...
- iOS开发之再探多线程编程:Grand Central Dispatch详解
Swift3.0相关代码已在github上更新.之前关于iOS开发多线程的内容发布过一篇博客,其中介绍了NSThread.操作队列以及GCD,介绍的不够深入.今天就以GCD为主题来全面的总结一下GCD ...
- iOS开发:创建真机调试证书及描述文件
iOS开发:创建真机调试证书及描述文件 关于苹果iOS开发,笔者也是从小白过来的,经历过各种困难和坑,其中就有关于开发证书,生产证书,in_house证书,add_Hoc证书申请过程中的问题,以及上架 ...
- iOS开发系列--并行开发其实很容易
--多线程开发 概览 大家都知道,在开发过程中应该尽可能减少用户等待时间,让程序尽可能快的完成运算.可是无论是哪种语言开发的程序最终往往转换成汇编语言进而解释成机器码来执行.但是机器码是按顺序执行的, ...
- 文顶顶iOS开发博客链接整理及部分项目源代码下载
文顶顶iOS开发博客链接整理及部分项目源代码下载 网上的iOS开发的教程很多,但是像cnblogs博主文顶顶的博客这样内容图文并茂,代码齐全,示例经典,原理也有阐述,覆盖面宽广,自成系统的系列教程 ...
随机推荐
- runtime获取一个控件的所有属性
控件的有些属性API并没有开放,可以通过runtime查看: unsigned int count; Ivar *ivarList = class_copyIvarList([UITextField ...
- Python 3.5.1 Syntax & APIs(Continue Updating..
print(x, end=' ') instead of print(x) to escape the default line-changing-output. print(str.ljust(si ...
- sql快速参考
SQL 语句 语法 AND / OR SELECT column_name(s)FROM table_nameWHERE conditionAND|OR condition ALTER TABLE A ...
- const与static的区别
const就是只读的意思,只在声明中使用;const修饰的数据类型是指常类型,常类型的变量或对象的值是不能被更新的. const的作用: (1)可以定义const常量,具有不可变性. (2)便于进行类 ...
- HDOJ--ACMSteps--2.1.8--Leftmost Digit-(取对数,数学)
Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input T ...
- StringWriter/PrintWriter在Java输出异常信息中的作用
闲来无事,看看JUnit的源代码.刚刚开始看就发现一段有趣的代码: public String trace() { StringWriter stringWriter = new StringWrit ...
- ExtJS4 的dom
Ext使用了三个核心的工具类对我们掌握的DOM进行了完美的封装. ┣ Ext.Element(几乎对DOM的一切进行了封彻底装) ┣ Ext.DomHelper(一个强大的操控UI界面的工具类) ┣ ...
- andorid 自定义view属性declare-styleable
1. reference:参考某一资源ID. (1)属性定义: <declare-styleable name = "名称"> <attr name = &quo ...
- android--listview设置高度
android:layout_height="25dp"这么设置根本就没有用. 我们必须要设置android:minHeight="25dp"这样才行.
- laravel 报错 mcrypt_decrypt(): Key of size 11 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported
修改app/config/app.php文件 将key设置成长度为16,24,32的字符串