Crash when launching from push notification with i

2019-04-13 07:41发布

问题:

If I launch my app from a push notification the app crash while showing splash screen.

How can I solve this issue?

The crash comes only with iOS9, while everything works with iOS8.

Thanks for the help!

This is my crash log:

Last Exception Backtrace:

0   CoreFoundation                  0x185900f5c __exceptionPreprocess + 124
1   libobjc.A.dylib                 0x19a4f3f80 objc_exception_throw + 56
2   CoreFoundation                  0x185900e2c +[NSException raise:format:arguments:] + 108
3   Foundation                      0x1867eff3c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
4   UIKit                           0x18b0f86a4 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2912
5   UIKit                           0x18b0f5300 -[UIApplication workspaceDidEndTransaction:] + 168
6   FrontBoardServices              0x18f6477ec -[FBSSerialQueue _performNext] + 184
7   FrontBoardServices              0x18f647b6c -[FBSSerialQueue _performNextFromRunLoopSource] + 56
8   CoreFoundation                  0x1858b85a4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
9   CoreFoundation                  0x1858b8038 __CFRunLoopDoSources0 + 540
10  CoreFoundation                  0x1858b5d38 __CFRunLoopRun + 724
11  CoreFoundation                  0x1857e4dc0 CFRunLoopRunSpecific + 384
12  UIKit                           0x18aec40c8 -[UIApplication _run] + 460
13  UIKit                           0x18aebef60 UIApplicationMain + 204
14  Sudoku                          0x1000c0444 main (main.m:17)
15  libdyld.dylib                   0x19ad1e8b8 start + 4

Here my code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSDictionary *aps = [userInfo objectForKey:@"aps"];
    NSLog(@"RECEIVE REMOTE NOTIFICATION - APS: %@", aps);

    //Notifica push tipo MATCH_REQUEST
    if ( [[userInfo objectForKey:@"type"] isEqualToString:@"MATCH_REQUEST"] == YES )
    {
        if (application.applicationState == UIApplicationStateInactive)
        {
            NSLog(@"Inactive");
            [self showRequestPushNotification:[aps objectForKey:@"alert"] withDictionary:userInfo];
        }
        else if (application.applicationState == UIApplicationStateBackground)
        {
            NSLog(@"Background");
            [self showRequestPushNotification:[aps objectForKey:@"alert"] withDictionary:userInfo];
        }
        else
        {
            NSLog(@"Active");
            [self showRequestPushNotification:[aps objectForKey:@"alert"] withDictionary:userInfo];
        }
    }

    //Notifica push tipo MATCH_GAME
    else if ( [[userInfo objectForKey:@"type"] isEqualToString:@"NEW_MATCH"] == YES )
    {
        if (application.applicationState == UIApplicationStateInactive)
        {
            NSLog(@"Inactive");
            [self showMatchPushNotification:[aps objectForKey:@"alert"] withDictionary:userInfo];
        }
        else if (application.applicationState == UIApplicationStateBackground)
        {
            NSLog(@"Background");
            [self showMatchPushNotification:[aps objectForKey:@"alert"] withDictionary:userInfo];
        }
        else
        {
            NSLog(@"Active");
            [self showMatchPushNotification:[aps objectForKey:@"alert"] withDictionary:userInfo];
        }
    }
}

SOLVED

The problem is the follows: if I try to show custom notification message while the app isn't in the Active State, the app crash. Before iOS 9 this bug does not appears. So, be careful with the applicationState and check the activeState before manage UIView or UIWindow (graphics objects in general).