zoukankan      html  css  js  c++  java
  • iOS指纹识别

     1 -(void)CreateFingerPrint{
     2     LAContext *myContext = [[LAContext alloc] init];
     3     NSError *authError = nil;
     4     NSString *myLocalizedReasonString = @"请验证已有指纹";
     5     
     6     // 判断设备是否支持指纹识别
     7     if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
     8         if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"zhiwenshibie"]isEqualToString:[Finance_Tools getUserID]]) {
    10             // 指纹识别只判断当前用户是否机主
    12             [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
    13                       localizedReason:myLocalizedReasonString
    14                                 reply:^(BOOL success, NSError *error) {
    15                                     if (success) {
    16                                         // User authenticated successfully, take appropriate action
    17                                         NSLog(@"指纹认证成功");
    18                                         dispatch_async(dispatch_get_main_queue(), ^{
    19 
    20                                         [self createTiXianDownload:[[NSUserDefaults standardUserDefaults] objectForKey:@"PassWord"]];
    21                                         });                                     
    26                                     } else {
    27                                         NSLog(@"指纹认证失败,%@",error.description);
    28                                
    29                                         dispatch_async(dispatch_get_main_queue(), ^{
    30                                             
    31                                             //回到主线程操作代码块
    32                                             if ([[@(error.code) stringValue] isEqualToString:@"-2"]||[[@(error.code) stringValue] isEqualToString:@"-4"]) {
    33                                             }else if ([[@(error.code) stringValue] isEqualToString:@"-3"]||[[@(error.code) stringValue] isEqualToString:@"-8"]||[[@(error.code) stringValue] isEqualToString:@"-1"]){
    34                                                 //失败原因,弹出弹框输入密码
    35                                                 
    36                                             }
    37                                             
    38                                         });
    39                                         
    40                                         
    41                                     }
    42                                 }];
    43             
    44         }else{
    45             //开启指纹识别
    46         }
    47     } else {
    48         // Could not evaluate policy; look at authError and present an appropriate message to user
    49         NSLog(@"TouchID设备不可用");
    50         // TouchID没有设置指纹
    51         // 关闭密码(系统如果没有设置密码TouchID无法启用)
    52         
    53//弹出弹框输入密码

    56}
    57}

    失败原因:

    1   NSLog(@"指纹认证失败,%@",error.description);
    2                                     // 错误码 error.code
    3                                     // -1: 连续三次指纹识别错误
    4                                     // -2: 在TouchID对话框中点击了取消按钮
    5                                     // -3: 在TouchID对话框中点击了输入密码按钮
    6                                     // -4: TouchID对话框被系统取消,例如按下Home或者电源键
    7                                     // -8: 连续五次指纹识别错误,TouchID功能被锁定,下一次需要输入系统密码
    8                                     
  • 相关阅读:
    2016某天闲谈
    APP测试入门篇之APP基础知识(001)
    windows服务器下frp实现内网穿透
    nginx使用与配置
    spring boot 实现优雅的关闭
    spring boot 自定义sql分页查询
    java获取类加载路径和项目根路径的5种方法
    linux下 启动node 和关闭node
    docker 安装 fastdfs
    docker 常用命令和常用容器启动
  • 原文地址:https://www.cnblogs.com/kfgcs/p/6378727.html
Copyright © 2011-2022 走看看