在应用程序未运行时处理推送通知(应用程序被终止)

我的问题似乎是这个重复,但它不是。 当应用程序被杀害,并没有在后台运行,如果我收到推送通知,并点击通知横幅,它工作正常。 “userInfo”不是空的,应用程序处理通知。 但是,如果我closures通知横幅,并通过点击应用程序图标打开应用程序,这个“userInfo”返回零。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { NSDictionary* userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if(userInfo != nil){ //Handling notification } } 

并且

 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ if([application applicationState] == UIApplicationStateActive) { NSLog(@"...1"); }else if([application applicationState] == UIApplicationStateInactive){ NSLog(@"...2"); }else if([application applicationState] == UIApplicationStateBackground){ NSLog(@"...2"); } completionHandler(UIBackgroundFetchResultNoData); } 

有没有办法处理这些通知,或者我应该自己处理?

没有您的应用程序只通知用于打开/启动您的应用程序的通知。

没有办法检测通知中心是否有任何通知为您的应用程序。 您需要自己在应用程序服务器中构build它。