Reputation: 630
I want to integrate TouchID in my application. Based on true fingerprint, I will let user authenticate/not authenticate. To do so, in viewWillAppear of my ViewController, I have written the following code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([AppConfig getSettingWithKey:APP_TOKEN_KEY] != nil ){
if ([AppConfig getIsTouchIDPreferred] == PREFERRED){
BOOL shouldAuthenticate: [MyTouchIDClass authenticateWithFingerPrint];
if (shouldAuthenticate == YES){
//normal flow
}
}
}
}
Here, authenticateWithFingerPrint does the main job and its code:
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
__block BOOL toBeReturned = NO;
if([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]){
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:@"Are you the device owner?"
reply:^(BOOL success, NSError *error) {
if(error){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"There was a problem verifying your identity."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
return;
}
if(success){
toBeReturned = YES;
return;
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"You are not the device owner."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
return;
}
}];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
return toBeReturned;
However, problem is that if block in the viewWillAppear method does not wait for authenticateWithFingerPrint method and returns false, meaning that even if user logs in, she won't be authenticated.
So, how to make if block wait for authenticateWithFingerPrint method?
Thanks :)
Upvotes: 0
Views: 89
Reputation: 1495
You should not attempt block the main thread while you wait for TouchID.
What you should probably do instead is insert a new ViewController ahead of the one you are trying to block access to and present the TouchID prompt over that screen. When successfully authenticated, push the ViewController you are restricting access to on to the stack.
Upvotes: 1