应用程序未运行时处理推送通知(应用已被杀死)

时间:2014-11-13 08:59:32

标签: ios objective-c notifications apple-push-notifications

我的问题似乎与this one重复,但事实并非如此。虽然应用程序已被终止并且未在后台运行,但如果我收到推送通知并单击通知横幅,则它可以正常工作。 " USERINFO"不是空的,应用程序处理通知。 但是如果我解除通知横幅并通过点击应用程序图标打开应用程序,这个" userInfo"返回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);
}

有没有办法处理这些通知,还是应该由我自己处理?

1 个答案:

答案 0 :(得分:3)

不会仅向您的应用通知用于打开/启动应用的通知。

无法检测到您的应用的通知中心是否有任何通知。您需要在自己的应用服务器中自行构建。

相关问题