When iOS8.2-app is running in the background, it does not receive any push notification,
while if it is running on the foreground, it receives the push notifications fine.
Any idea what is going on ?
Running on CloudKit Development
mode, the subscription is for add,edit,and remove, and using the following 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);
}