Touch API is very slow

I followed the recommendations as well as an example of the Touch ID API from the Apple documentation. I used this example in my applications. I was able to log in using Touch ID. But the problem is that her responsiveness is very slow. After I put my finger on the touch identifier for at least 10 seconds, I have to wait to check for success / failure. I used the code in the application delegate file. I also tested various applications, but the result was the same “delayed response”. Guys, please help me in this case.

+7
authentication ios objective-c touch-id
source share
3 answers
LAContext *myContext = [[LAContext alloc] init]; NSError *authError = nil; NSString *myLocalizedReasonString = <#String explaining why app needs authentication#>; if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError *error) { if (success) { // User authenticated successfully, take appropriate action dispatch_async(dispatch_get_main_queue(), ^{ // write all your code here }); } else { // User did not authenticate successfully, look at error and take appropriate action switch (error.code) { case LAErrorAuthenticationFailed: NSLog(@"Authentication Failed"); break; case LAErrorUserCancel: NSLog(@"User pressed Cancel button"); break; case LAErrorUserFallback: NSLog(@"User pressed \"Enter Password\""); break; default: NSLog(@"Touch ID is not configured"); break; } NSLog(@"Authentication Fails"); } }]; } else { // Could not evaluate policy; look at authError and present an appropriate message to user } 
+22
source share

You should display warnings in the main thread with

 dispatch_async(dispatch_get_main_queue(), ^{ //update ui }); LAContext *context = [[LAContext alloc] init]; NSError *error = nil; if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { // Authenticate User NSError *error = nil; if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Please verify that you are the device owner in order to place the order" reply:^(BOOL success, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ 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) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"You are the device owner!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; } 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]; 

}

+6
source share

Like all of the above, you need to make a UI on the main thread, for Swift 3.0 this is:

 myContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { (success, evaluateError) in DispatchQueue.main.async { if (success) { //success } else { //failure } } } 
+1
source share

All Articles