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];
    }

  • 相关阅读:
    一个很好的菜单源码
    在盗版xp下安装ie7正式版 
    [导入]买新手机了
    [导入]手机解锁全集
    12种找工作方式的成功率
    Kerberos的原理 3
    Kerberos的原理 4
    Kerberos的原理 1
    jQuery 原理的模拟代码 6 代码下载
    Hashtable 中的键值修改问题
  • 原文地址:https://www.cnblogs.com/sayimba/p/5698000.html
Copyright © 2011-2022 走看看