- (void)touchIdIntegration{
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:@"Authenticate via Touch ID to unlock the app"
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
[[AppManager instance].helpManager setDontShowInterstialAd:TRUE];
[[AppManager instance].cycleManager setUserAuthenticated:TRUE];
[self.delegate showAlertViewsOnServerData];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
switch (error.code) {
case kLAErrorAuthenticationFailed:
NSLog(@"kLAErrorAuthenticationFailed");
break;
case kLAErrorTouchIDNotEnrolled:
NSLog(@"kLAErrorTouchIDNotEnrolled");
break;
case LAErrorPasscodeNotSet:
NSLog(@"LAError code ");
break;
default:
break;
}
});
}
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
self.m_imgFingerPrint.hidden = YES;
NSLog(@"LAError code %ld",authError.code);
NSString *alertMessage =nil;
switch (authError.code) {
case kLAErrorAuthenticationFailed:
{
alertMessage = @"kLAErrorAuthenticationFailed" ;
}
break;
case kLAErrorTouchIDNotEnrolled:
alertMessage = @"kLAErrorTouchIDNotEnrolled" ;
break;
case LAErrorPasscodeNotSet:
alertMessage = @"LAErrorPasscodeNotSet" ;
break;
default:
break;
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:alertMessage
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alertView show];
});
}
}
我不希望每次用户移动到此屏幕时都会弹出。是否可能?请告诉我。
无论如何都要提前感谢。
答案 0 :(得分:0)
请勿撰写此代码viewDidLoad
或viewDidAppear
。只有在绝对需要提出touchID时才写它。