OC语言实现指纹识别

来源:互联网 发布:给软件添加注册码 编辑:程序博客网 时间:2024/06/03 21:09

iOS开发交流群:484884085

欢迎大家加入!


简单实现指纹识别的方法,大虾勿喷~

1、引入类

#import <LocalAuthentication/LocalAuthentication.h>

2、实现方法

- (void) anthTouchID:(NSString *) describe complete:(void(^)(NSString *backStr)) complete{    //检查操作系统是否达到指纹识别要求    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){                //检查Touch ID是否可用        LAContext *anthContext = [[LAContext alloc]init];        NSError *error = [[NSError alloc]init];                BOOL touchIDAvailable = [anthContext canEvaluatePolicy:kLAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];                if (touchIDAvailable) {                        //指纹识别可用,获取验证结果            [anthContext evaluatePolicy:kLAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:describe reply:^(BOOL success, NSError * _Nullable error) {                                    //加入主线程中执行                    dispatch_async(dispatch_get_main_queue(), ^{                        if (success) {                                                        //验证通过                            if (complete) {                                complete(@"success");                            }                                                    } else {                                                        //验证失败                            if (complete) {                                complete(error.localizedDescription);                            }                        }                    });            }];                    } else {                        //指纹识别不可用            if (complete) {                complete(error.localizedDescription);            }        }            } else {                //设备操作系统版本过低        if (complete) {            complete(@"Device system version too low.");        }    }}

3、调用方法

[self anthTouchID:@"指纹识别的测试调用" complete:^(NSString *backStr) {        NSLog(@"输出:%@",backStr);    }];


0 0