iOS指纹识别技术

实用原理:

指纹识别技术就是把一个人同他的指纹对应起来,通过比较他的指纹和预先保存的指纹进行比较,就可以验证他的真实身份。
指纹识别概念阐述:http://baike.so.com/doc/6246764-6460171.html

在iOS中的发展过程:

苹果从iPhone5S开始,具有指纹识别技术。但是,是从iOS8.0之后程序员具有使用指纹识别的权利——苹果允许第三方 App 使用 Touch ID 实现免密码登陆。

苹果在iPhone 5s上采用的指纹识别技术来自AuthenTec。2012年6月,苹果收购了这家公司。在被苹果收购之前,AuthenTec是全球最大的指纹识别芯片供应商,拥有名为TurePrint的专利技术,可以读取皮肤表皮之下的真皮层信息。

实际应用:

目前QQ、微信、支付宝等主流APP大都已支持指纹登录或指纹支付。

使用时涉及关键点:
  1. iOS提供了LocalAuthentication框架,以便我们使用指纹识别。
  2. 指纹识别Touch ID提供3+2共5次指纹识别机会,如果五次指纹识别全部错误,就需要手动输入密码。
代码技术流程:

首先导入框架#import <LocalAuthentication/LocalAuthentication.h>

  1. 判断系统版本
  2. LAContext : 本地验证对象上下文
  3. 判断生物识别技术是否可用canEvaluatePolicy
  4. 如果可用,开始调用方法开始使用指纹识别
    注意:
    1、代码中最好做错误处理
    2、如果指纹识别成功后,有操作需要更新UI,那么一定在主线程中。

    具体看代码吧!

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //1. 判断系统版本 if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {

     //2. LAContext : 本地验证对象上下文
     LAContext *context = [LAContext new];
    
     //3. 判断是否可用
     //Evaluate: 评估  Policy: 策略,方针
     //LAPolicyDeviceOwnerAuthenticationWithBiometrics: 允许设备拥有者使用生物识别技术
     if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
         NSLog(@"对不起, 指纹识别技术暂时不可用");
     }
    
     //4. 开始使用指纹识别
     //localizedReason: 指纹识别出现时的提示文字, 一般填写为什么使用指纹识别
     [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"开启了指纹识别, 将打开隐藏功能" reply:^(BOOL success, NSError * _Nullable error) {
    
         if (success) {
             NSLog(@"指纹识别成功"); 
             // 指纹识别成功,回主线程更新UI,弹出提示框
             dispatch_async(dispatch_get_main_queue(), ^{
    
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"指纹识别成功" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
                 [alertView show];
             });
    
         }
    
         if (error) {
    
             // 错误的判断chuli
    
             if (error.code == -2) {
                 NSLog(@"用户取消了操作");
    
                 // 取消操作,回主线程更新UI,弹出提示框
                 dispatch_async(dispatch_get_main_queue(), ^{
    
                     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用户取消了操作" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
                     [alertView show];
    
                 });
    
             } else {
                 NSLog(@"错误: %@",error);
             // 指纹识别出现错误,回主线程更新UI,弹出提示框
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:error delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
                 [alertView show];
             }
    
         }
    
     }];

    } else {

     NSLog(@"对不起, 该手机不支持指纹识别");

    }
    }`


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值