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

  • 相关阅读:
    Android Studio代码自己主动检測错误提示
    uva 1567
    UWP 新手教程2——怎样实现自适应用户界面
    远程服务的使用场景
    本地服务和远程服务
    本地应用调用远程服务中的方法
    混合方式开启服务
    绑定服务抽取接口
    绑定服务调用服务里的方法
    bind绑定服务的生命周期
  • 原文地址:https://www.cnblogs.com/sayimba/p/5698000.html
Copyright © 2020-2023  润新知