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);
}