当我尝试在我的应用上使用TouchID时,它会挂起很长一段时间,然后有时会崩溃,有时会最终通过。我从来没有尝试过使用Touch ID的任何东西,所以对我来说这一切都非常新鲜。我的代码是:
-(IBAction)touchID {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *student = [defaults objectForKey:@"firstName"];
NSString *usingTouch = [defaults objectForKey:@"useTouchID"];
if ([usingTouch isEqualToString:@"Yes"]) {
[passwordfield removeFromSuperview];
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:@"Are you the device owner?"
reply:^(BOOL success, NSError *error) {
if (error) {
NSLog(@"%@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"There was a problem verifying your identity."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
return;
}
else if (success) {
NSString *nope = @"Yes";
[defaults setObject:nope forKey:@"firstName"];
[defaults synchronize];
[self updatetheview];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"You are not the device owner."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
}];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
//Perform Touch ID Code
}
}
控制台一遍又一遍地显示这一点,然后立即按照您的预期立即行动:
Stack:( 0 CoreFoundation 0x000000018359cf60 + 148 1 libobjc.A.dylib 0x0000000198a47f80 objc_exception_throw + 56 2 CoreFoundation 0x000000018359ce90 + 0 3 Foundation 0x00000001845bb2d8 + 88 4 Foundation 0x0000000184441a1c + 56 5 Foundation 0x000000018443d5dc + 260 6 UIKit 0x0000000188c378c4 + 64 7 UIKit 0x0000000188b2aa78 + 240 8 UIKit 0x0000000188b2a32c + 116 9 UIKit 0x0000000188b2a1b8 + 504 10 UIKit 0x0000000188e3c834 + 228 11 UIKit 0x0000000188b28bf8 + 412 12 Fritch 0x0000000100186f40 -[DirectoryViewController updatetheview] + 180 13 Fritch 0x0000000100186cac __34-[DirectoryViewController touchID]_block_invoke + 316 14 LocalAuthentication 0x000000018599ee28 + 72 15 LocalAuthentication 0x000000018599e7e4 + 256 16 LocalAuthentication 0x000000018599b004 + 324 17 LocalAuthentication 0x000000018599b168 + 128 18 CoreFoundation 0x00000001835a2a70 + 144 19 CoreFoundation 0x00000001834a04d4 + 284 20 Foundation 0x00000001845c5b4c + 20 21 Foundation 0x00000001845c5940 + 796 22 Foundation 0x00000001845c79c8 + 292 23 libxpc.dylib 0x00000001994a0c80 + 28 24 libxpc.dylib 0x00000001994a0c24 + 40 25 libdispatch.dylib 0x000000010051dc68 _dispatch_client_callout + 16 26 libdispatch.dylib 0x000000010052a780 _dispatch_queue_drain + 1036 27 libdispatch.dylib 0x0000000100521958 _dispatch_queue_invoke + 464 28 libdispatch.dylib 0x000000010051dc68 _dispatch_client_callout + 16 29 libdispatch.dylib 0x000000010052cec8 _dispatch_root_queue_drain + 2344 30 libdispatch.dylib 0x000000010052c590 _dispatch_worker_thread3 + 132 31 libsystem_pthread.dylib 0x000000019946d470 _pthread_wqthread + 1092 32 libsystem_pthread.dylib 0x000000019946d020 start_wqthread + 4 )
答案 0 :(得分:3)
主线程上未调用reply
的{{1}}块。您需要确保evaluatePolicy
块中的所有UI代码都在主线程上完成。