【发布时间】:2016-08-10 09:43:24
【问题描述】:
我想在应用程序中保存一些推送通知数据。但是如果用户通过在多任务查看器上向上滑动应用程序来终止应用程序(暂停或未运行状态),我无法保存数据。我使用了 application:didReceiveRemoteNotification:fetchCompletionHandler :处理它。但我仍然无法保存推送通知数据
我已经设置了这样的应用设置
和有效载荷,
{
"aps" : {
"alert" = "Notification with custom payload",
},
"content-available" = 1
}
而 application: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);
}
}
【问题讨论】:
-
@Ewan Mellor ,@Anbu.Karthik .Ok .告诉我,当应用程序处于挂起状态时,有什么方法可以保存推送通知数据?
标签: ios objective-c push-notification apple-push-notifications