当iOS8.2-app在后台运行时,它不会收到任何推送通知,
知道发生了什么事吗?
在CloudKit开发模式下运行,订阅用于添加,编辑和删除,并使用以下didReceiveRemoteNotification:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"Push received."); NSDictionary * apsDict = [userInfo objectForKey:@"aps"]; Nsstring * alertText = [apsDict objectForKey:@"alert"]; //Todo: get the record information from the notification and create the appropriate message string. if(application.applicationState == UIApplicationStateActive) { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:alertText delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; [alert show]; } else { if([application currentUserNotificationSettings].types & UIUserNotificationTypeAlert) { UIlocalnotification * localnotification = [[UIlocalnotification alloc] init]; localnotification.alertBody = NSLocalizedString(@"alert body",nil);; localnotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2]; [application presentlocalnotificationNow:localnotification]; } } completionHandler(UIBackgroundFetchResultNoData); }
解决方法
当您转到应用程序设置功能时,是否为背景模式启用了远程通知?
看这个截图:
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .sound,categories: nil)) application.registerForRemoteNotifications()
在您的订阅中,您是否为CKNotificationInfo发送alertBody或alertLocalizationKey?如果您这样做,那么您将从操作系统获得通知,而您无需设置本地通知.
更新:正如下面提到的Porton,填写alertBody解决了这个问题.