处理推送通知时,应用程序没有运行程序(App被杀害)

问题描述:

我的问题似乎是重复的this 之一,但它不是。当应用程序被杀害并在后台没有运行,如果我收到推送通知,并点击该通知的旗帜,它工作正常。 用户信息不为空并且应用程序处理通知。 BUT 如果我解雇通知的旗帜,并通过点击应用程序图标打开应用程序,这种用户信息返回nil。

My problem seems to be duplicate of this one,but it's not. While application is killed and not running in the background, if I receive push notification and clicked the notification banner, it works fine. "userInfo" isn't empty and application handles the notification. BUT if i dismiss the notification banner and open the app via clicking the application icon, this "userInfo" returns nil.

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

有什么办法来处理这​​些通知,或者我应该用我自己的处理?

Is there any way to handle these notifications or should I handle them by my own ?

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

No your app is only informed about the notification that is used to open/launch your app.

有没有办法检测有在通知中心,为您的应用程序的任何通知。您需要在您的应用程序服务器,以这个自己搭建。

There is no way to detect of there are any notification in the notification center for your app. You need to build this yourself in your apps server.