ios touchID

一个人想着一个人 提交于 2020-02-24 23:13:00

 //需要导入支持库LocalAuthentication.framework

#import <LocalAuthentication/LocalAuthentication.h>

//TouchID是否验证成功

-(void)touchIDSuccess{

    __block NSString *msg;

    

    [self.context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics

                 localizedReason:NSLocalizedString(@"解锁 合时代金融", nil)

                           reply:^(BOOL success, NSError *error) {

                               if (success) {

                                   msg = [NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_SUCCESS", nil)];

                               }else{

                                   msg = [NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_WITH_ERROR", nil), error.localizedDescription];

                               }

                               NSLog(@"msg:%@",msg);

                               dispatch_async(dispatch_get_main_queue(), ^{

                                   self.touchIDResult.text = msg;

                               });

    }];

    

    

}

 

 

 

 

//TouchID是否有效

-(BOOL)isValidateTouchID{

    __block NSString *message;

    NSError *error;

    BOOL success;

    

    success = [self.context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics

                                        error:&error];

    

    if (success) {

        message = [NSString stringWithFormat:NSLocalizedString(@"TOUCH_ID_IS_AVAILABLE", nil)];

    }else{

        message = [NSString stringWithFormat:NSLocalizedString(@"TOUCH_ID_IS_NOT_AVAILABLE", nil)];

    }

    

    NSLog(@"message:%@",message);

    return success;

}

- (IBAction)touchIDAction:(id)sender {

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) {

        self.context = [[LAContext alloc] init];

        self.touchIDResult.text = @"指纹识别";

        

        if ([self isValidateTouchID]) {

            [self touchIDSuccess];

        }

    }

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!