I looked a lot questions and answers for the same issue.
And What I know now is that
- 'didReceiveRemoteNotification' is not called when the app is background.
- didReceiveRemoteNotification is just called when app is foreground or when user comes to app by tapping notification if its in background.
- application:didFinishLaunchingWithOptions: is called when user taps on notification to open the app if its killed.
My situation is below:
- I'm using parse to push and get notification.
- I'm successful getting notification when app is foreground and I'm handling data and show alert and list notification at notification list.
- But I can not get notification when app is background or killed.
- But I check my app can get notification when my app is background or killed when using 'custom audience' of Parse as I want. (Like other famous applications)
What I want to is I want to get notification when app is background or killed like when I use 'custom audience' of Parse. But when I use just API of Parse , it doesn't work as i want.
Is there anything I'm missing now?
My registering code is below:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"didReceiveRemoteNotification executed : %@",userInfo);
NSInteger bettingIDX = [[userInfo objectForKey:@"betting_idx"] integerValue];
NSString *message = [userInfo objectForKey:@"message"];
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = [NSString stringWithFormat:@"%@",message];
NSUUID *uuid = [NSUUID UUID];
NSString *notificationKey = [uuid UUIDString];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSLog(@"DeviceToken : %@", deviceToken );
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[Parse setApplicationId:@"applicationID"
clientKey:@"clientID"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}