【发布时间】:2016-04-19 06:09:52
【问题描述】:
我想在我的应用程序中集成 TouchID。基于真实指纹,我将让用户进行身份验证/不进行身份验证。为此,在我的 ViewController 的 viewWillAppear 中,我编写了以下代码:
- (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
}
}
}
}
这里,authenticateWithFingerPrint 完成主要工作及其代码:
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;
但是问题是viewWillAppear方法中的block如果不等待authenticateWithFingerPrint方法返回false,意味着即使用户登录也不会被认证。
那么,如何让 if 块等待 authenticateWithFingerPrint 方法?
谢谢:)
【问题讨论】:
标签: fingerprint touch-id