Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone App Crash with error [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:]

I have an iPhone App in the app store which is using Touch ID. If Touch ID is enabled, the user is authenticated with it, else user needs to enter his PIN to login to the application.

After IOS 10.1 release, when I checked the crash report, the crash count has increased. From the crash report, it is pointing on [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] and when I opened the app in Xcode, it is focussing on [self dismissViewControllerAnimated:YES completion:nil];.

Crash Report

The code I have written is as below:

-(void) showTouchIDAuthentication{

    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    NSString *myLocalizedReasonString = @"Authenticate using your finger to access My Account Menu.";
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:myLocalizedReasonString
                            reply:^(BOOL success, NSError *error) {
                                if (success) {
                                    NSLog(@"User is authenticated successfully");
                                    [self dismissViewControllerAnimated:YES completion:nil];
                                } else {
   }];
    }

}

When I tested in iPhone 6, IOS 10, everything is working fine. Don't know how to simulate the issue.

Can anyone please figure out if I am missing something? Please help me out in resolving this crash issue.

like image 983
Abin Koshy Cheriyan Avatar asked Sep 26 '16 05:09

Abin Koshy Cheriyan


1 Answers

Usually completion handlers are not running on main thread. All UI related stuff must be done on main thread (including dismissing a view controller).

I suggest to add the dismiss line on a main thread block like this:

-(void) showTouchIDAuthentication{

LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Authenticate using your finger to access My Account Menu.";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
              localizedReason:myLocalizedReasonString
                        reply:^(BOOL success, NSError *error) {
                            if (success) {
                                NSLog(@"User is authenticated successfully");

                                [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
                                    [self dismissViewControllerAnimated:YES completion:nil];
                                }];

                            } else {
   }];
    }

}
like image 86
Fidel López Avatar answered Nov 06 '22 01:11

Fidel López