收到推送通知后,为什么launchOptions为零?

时间:2014-03-26 11:28:03

标签: ios objective-c push-notification

通过点击通知获取推送通知并打开应用后,在nil中收到didFinishLaunchWithOptions的可能原因是什么?我已经仔细检查过应用程序已停止,而不仅仅是在后台。 nil仍然始终写入日志。

我在didFinishLaunchWithOptions中没有做任何特别的事情,这是代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [MA init];
    NSLog(@"%@", launchOptions);
    if (!launchOptions) {
        return YES;
    }
    id userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

    if (userInfo[@"aps"] && userInfo[@"id"]) {
        MAResult* result = [[MA data] resultById:userInfo[@"id"]];
        if (result) {
            [((UINavigationController *)self.window.rootViewController) pushViewController:[[MATaskDetails alloc] initWithResults:result] animated:YES];
        }
    }

    return YES;
}

2 个答案:

答案 0 :(得分:0)

您可以尝试使用didReceiveRemoteNotification委托方法

- (void)application:(UIApplication *)application
   didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[MA init];
    NSLog(@"%@", Received Notification);
    if (userInfo[@"aps"] && userInfo[@"id"]) {
        MAResult* result = [[MA data] resultById:userInfo[@"id"]];
        if (result) {
            [((UINavigationController *)self.window.rootViewController) pushViewController:[[MATaskDetails alloc] initWithResults:result] animated:YES];
        }
    }
  }

希望它可以帮助你....!

答案 1 :(得分:-1)

如果应用处于前台模式,则会通过application:didReceiveRemoteNotification:

接收推送通知

但如果应用程序未处于前台模式,则推送通知将传递到application:didFinishLaunchingWithOptions:

所以我相信你以前台模式申请并application:didFinishLaunchingWithOptions: 根本没有被召唤。