application:didReceiveRemoteNotification:fetchCompletionHandler:NOT称为iOS 9

时间:2016-08-10 09:43:24

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

我想在应用程序中保存一些推送通知数据。但是,如果用户通过在多任务查看器上刷起应用程序来终止应用程序(挂起或未运行状态),则无法保存数据。我使用的应用程序:didReceiveRemoteNotification:fetchCompletionHandler :处理它。但我仍然无法保存推送通知数据

我已经设置了像这样的应用程序设置

enter image description here

enter image description here

和Payload,

 {
    "aps" : {
       "alert" = "Notification with custom payload",
    },
   "content-available" = 1
 }

应用程序:didReceiveRemoteNotification:fetchCompletionHandler:看起来像这样

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    if(application.applicationState == UIApplicationStateInactive) {

        NSLog(@"Inactive");

        //Show the view with the content of the push

        completionHandler(UIBackgroundFetchResultNewData);

    } else if (application.applicationState == UIApplicationStateBackground) {

        NSLog(@"Background");

        NSString *info = [[userInfo valueForKey:@"aps"]valueForKey:@"alert"];

        completionHandler(UIBackgroundFetchResultNewData);

    } else {

        NSLog(@"Active");

        //Show an in-app banner

        completionHandler(UIBackgroundFetchResultNewData);

    }
}

1 个答案:

答案 0 :(得分:0)

这是完全正常的。如果您检查设备的控制台日志,您将看到来自系统的消息,指出它不会唤醒应用程序,因为它已被用户终止。