我正在尝试设置我的应用,因此当收到推送时,它首先会在显示推送通知之前获取新消息。在我的推送通知中,我有content-available = 1 set以及Plist中启用的开关。我已经实施了:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
if([[userInfo objectForKey:@"aps"] objectForKey:@"content-available"]){
NSLog(@"Doing the background refresh");
UINavigationController *navigationController=(UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
MYViewController *MYViewController = (MYViewController *)[[navigationController viewControllers] objectAtIndex:1];
[myViewController.currentUser refreshMessagesArrayWithCompletionHandler:^(BOOL successful, BOOL newMiaos) {
NSLog(@"messages refreshed the array now has %lu messages",(unsigned long)[myViewController.currentUser.messages count]);
handler(UIBackgroundFetchResultNewData);
}];
}
}
应用程序推送将在后台完成或刷新期间进入。当然它应该在之后进入。我处理这个错误吗?我是否需要发送静默推送通知并在完成阻止后显示local
通知?
答案 0 :(得分:1)
我遇到了与你类似的问题,
我通过发送像这样的推送通知来解决它
{
"alert": null,
"content-available": 1,
"data-id" : "some_data_id"
}
在这种情况下,不会显示推送通知, 因此,在后台提取中,您可以执行提取并触发本地通知。