Приложение Touch ID Crashing
При попытке использовать 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
}
}
Консоль показывает это снова и снова, прежде чем, наконец, действовать так, как вы ожидаете, немедленно:
Стек:( 0 CoreFoundation 0x000000018359cf60 + 148 1 libobjc.A.dylib 0x0000000198a47f80 objc_exception_throw + 56 2 CoreFoundation 0x000000018359ce90 + 0 3 Фундамент 0x00000001845bb2d8 + 88 4 Фонд 0x0000000184441a1c + 56 5 Фонд 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 Фрич 0x0000000100186f40 -[DirectoryViewController updatetheview] + 180 13 Фрич 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 Фонд 0x00000001845c5b4c + 20 21 Фонд 0x00000001845c5940 + 796 22 Фонд 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 0x000000019946d0 0x0 0 0 0 0 0 0 0 2 0 0 0 5 5 5 0 0 0 0 0 8 0 0 0 5 0 0 0 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 2 0 0 0 2 0 0 0 2 0 0 0 2 0 0 0 2 0 0 0 2 0 0 0 2 0 0 0. 0
1 ответ
Решение
reply
блок из evaluatePolicy
не вызывается в главном потоке. Вы должны убедиться, что весь ваш код пользовательского интерфейса в reply
блок делается на основной поток.