使用iOS 9从推送通知启动时崩溃

时间:2015-09-22 16:11:55

标签: ios objective-c crash apple-push-notifications ios9

如果我通过推送通知启动我的应用,则应用会在显示启动画面时崩溃。

我该如何解决这个问题?

崩溃只发生在iOS9上,而一切都适用于iOS8。

感谢您的帮助!

这是我的崩溃日志:

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

这是我的代码:

- (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];
        }
    }
}

解决

问题如下:如果我在应用程序未处于活动状态时尝试显示自定义通知消息,则应用程序崩溃。在iOS 9之前,此错误不会出现。因此,在管理UIView或UIWindow(通常是图形对象)之前,请注意applicationState并检查activeState。

0 个答案:

没有答案