在应用程序未运行时处理推送通知(应用程序被杀死) [英] Handling push notifications when app is not running (App is Killed)

查看:37
本文介绍了在应用程序未运行时处理推送通知(应用程序被杀死)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题似乎与这个问题重复,但事实并非如此.当应用程序被终止并且不在后台运行时,如果我收到推送通知并单击通知横幅,它工作正常.用户信息"不为空,应用程序处理通知.但是如果我关闭通知横幅并通过单击应用程序图标打开应用程序,这个userInfo"返回零.

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.

这篇关于在应用程序未运行时处理推送通知(应用程序被杀死)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆