iOS指纹识别功能

来源:互联网 发布:淘宝四大化妆刷店 编辑:程序博客网 时间:2024/05/01 21:04

第一步:老地方导入第三方库:LocalAuthentication.framework


第二步:在需要指纹解锁的地方导入头文件

#import "LocalAuthentication/LAContext.h"

第三步:关键代码

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    LAContext * muContext = [[LAContext alloc]init];    NSError * autherror = nil;    NSString *myLocalizedReasonString = @"We need to verify your fingerprint to confirm your identity";    if ([muContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&autherror]) {        [muContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError * _Nullable error) {            if (success) {                NSLog(@"指纹验证成功");                            }else{                //验证三次不成功就会走这个方法                NSLog(@"指纹验证失败");            }        }];            }else{                NSLog(@"系统没有开启指纹模式,或者用户多次验证指纹失败!");    }}

结束!!!!



0 0
原创粉丝点击