iOS8.2-app在后台运行时,不会收到任何推送通知,
而如果它在前台运行,它可以很好地接收推送通知。
知道发生了什么事吗?
运行于CloudKit Development
模式,订阅用于添加、编辑和删除,并使用以下内容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);
}
当您进入应用程序设置功能时,是否为后台模式启用了远程通知?
See this screenshot:
除此之外,您是否注册了所有通知类型,如下所示:
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil))
application.registerForRemoteNotifications()
在您的订阅中,您是否为 CKNotificationInfo 发送alertBody 或alertLocalizationKey?如果您这样做,那么您将已经从操作系统收到通知,并且无需设置本地通知。
更新:正如下面Porton提到的,这个问题通过填写alertBody解决了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)