【问题标题】:Why launchOptions is nil after receiving push notification?为什么在收到推送通知后 launchOptions 为零?
【发布时间】:2014-03-26 11:28:02
【问题描述】:

在收到推送通知并通过点击通知打开应用程序后,在didFinishLaunchWithOptions 中收到nil 的可能原因是什么?我已经仔细检查了应用程序是否已停止,而不仅仅是在后台。并且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;
}

【问题讨论】:

  • payload里面有什么?

标签: ios objective-c push-notification


【解决方案1】:

您可以尝试使用 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];
        }
    }
  }

希望对您有所帮助....!

【讨论】:

    【解决方案2】:

    如果应用程序处于前台模式,则它会通过application:didReceiveRemoteNotification: 接收推送通知

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

    所以我相信你的应用程序处于前台模式和application:didFinishLaunchingWithOptions: 根本没有被调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-07
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      相关资源
      最近更新 更多