简体   繁体   English

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

[英]Handling push notifications when app is not running (App is Killed)

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. “ userInfo”不为空,应用程序处理通知。 BUT if i dismiss the notification banner and open the app via clicking the application icon, this "userInfo" returns nil. 但是,如果我关闭通知横幅并通过单击应用程序图标打开应用程序,则此“ userInfo”将返回nil。

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

    }
}

and also 并且

-(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. 您需要自己在应用服务器中构建它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM