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

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    
    {
        //1. 判断系统版本
        if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
            //可以使用指纹识别 --> 5S 以后的机型
            LAContext *context = [[LAContext alloc] init];
            if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
                
                // 可以使用
                //3. 开始启用指纹识别
                //localizedReason : 显示在界面上的原因, 一般用于提示用户, 为什么要使用此功能
                [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"请验证指纹, 以打开高级隐藏功能" reply:^(BOOL success, NSError * _Nullable error) {
                    
                    //判断是否成功
                    if (success) {
                        //4. 指纹识别在更新 UI 时, 一定要注意, 在主线程更新
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [self createUIAlertController:@"验证成功"];
                        });
                                            
                    } else {
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [self createUIAlertController:@"验证失败"];
                        });
                    }
                    // 判断错误 如果需要区分不同的错误来提示用于, 必须判断 error
                    if (error) {
                        
                        NSLog(@"error Code: %ld",error.code);
                        
                        NSLog(@"error : %@",error.userInfo);
                    }
                }];
            } else {
                
                NSLog(@"对不起, 5S 以上机型才能使用此功能");
            }
            
        } else {
            
            NSLog(@"对不起, 系统版本过低");
            
        }
        
    }
    -(void)createUIAlertController:(NSString*)title
    {
        UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * action =[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        UIAlertAction * action1 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }];
        [alert addAction:action1];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:nil];
    }

  • 相关阅读:
    [bzoj1568]李超线段树模板题(标志永久化)
    [tyvj1860]后缀数组
    [poj3264]rmq算法学习(ST表)
    LintCode-82.落单的数
    LintCode-53.翻转字符串
    LintCode-56.两数之和
    LintCode-379.将数组重新排序以构造最小值
    LintCode-5.第k大元素
    LintCode-3.统计数字
    LintCode-4.丑数 II
  • 原文地址:https://www.cnblogs.com/sayimba/p/5698000.html
Copyright © 2011-2022 走看看