ios touchID
//需要导入支持库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];
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。