zoukankan      html  css  js  c++  java
  • apple面容、指纹验证使用

    1、导入包

    #import <LocalAuthentication/LocalAuthentication.h>
    

    2、使用

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
        [super touchesBegan:touches withEvent:event];
        
        LAContext *lacontext = [[LAContext alloc] init];
        BOOL support = [lacontext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:NULL];
        if(@available(iOS 11.0, *)) {
            if([lacontext respondsToSelector:@selector(biometryType)]){
                if(lacontext.biometryType == LABiometryTypeFaceID) {
                    CHLog(@"面容ID登录");
                    // LAPolicyDeviceOwnerAuthenticationWithBiometrics:
                    [lacontext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                              localizedReason:@"面容ID登录..."
                                        reply:^(BOOL success, NSError * _Nullable error) {
                        if (success) {
                            
                        }
                        else {
                            LAError code = error.code;
                            switch (code) {
                                case LAErrorAuthenticationFailed:
                                    CHLog(@"身份验证失败");
                                    break;
                                case LAErrorUserCancel:
                                    CHLog(@"用户在认证时点击取消");
                                    break;
                                case LAErrorUserFallback:
                                    CHLog(@"用户点击输入密码取消指纹/面容验证");
                                    break;
                                case LAErrorSystemCancel:
                                    CHLog(@"身份认证被系统取消(按下Home键或电源键)");
                                    break;
                                case LAErrorPasscodeNotSet:
                                    CHLog(@"设备未设置密码");
                                    break;
                                case LAErrorTouchIDNotAvailable:
                                    CHLog(@"该设备指纹验证不可用");
                                    break;
                                case LAErrorTouchIDNotEnrolled:
                                    CHLog(@"用户未录入指纹");
                                    break;
                                case LAErrorTouchIDLockout:
                                    CHLog(@"连续五次密码错误,FaceID被锁定.");
                                    break;
                                case LAErrorAppCancel:
                                    CHLog(@"用户不能控制情况下App被挂起.");
                                    break;
                                default:
                                    break;
                            }
                        }
                    }];
                }
                else if(lacontext.biometryType == LABiometryTypeTouchID) {
                    CHLog(@"指纹登录");
                }
                else {
                    CHLog(@"未授权");
                }
            }
        }
    }
    
  • 相关阅读:
    Android开发学习总结(一)——搭建最新版本的Android开发环境
    数据库服务器编码,数据库编码,数据库表编码,数据库表字段编码
    webservice(二)简单实例
    webservice(一) 概念
    JAVA的StringBuffer类
    Log4J日志配置详解
    如何配置使用 Log4j
    使用MyBatis Generator自动创建代码
    Spring MVC POST中文乱码解决方案
    JSP开发中对jstl的引用方式(标签库引用)
  • 原文地址:https://www.cnblogs.com/CH520/p/13174702.html
Copyright © 2011-2022 走看看