Problem with iOS and data messages. It is indicated here in which
In iOS, FCM saves a message and delivers it only when the application is in the foreground and has established an FCM connection.
Thus, MUST work. Something similar to mine:
Send 2 push notifications:
1) Normal to wake up a user's phone / initiate when the application is in the background using this code:
{ "to" : "/topics/yourTopicName", "notification" : { "priority" : "Normal", "body" : "Notification Body like: Hey! There something new in the app!", "title" : "Your App Title (for example)", "sound" : "Default", "icon" : "thisIsOptional" } }
2) Data notification that will be launched when the user opens the application
{ "to" : "/topics/yourTopicName", "data" : { "yourData" : "1", "someMoreOfYourData" : "This is somehow the only workaround I've come up with." } }
and thus, by the method - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage process your data:
- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
I also left this code to trigger a notification inside the application (create a local notification), because you can use it to create a banner with blocking, which is probably why the user receives the notification again even when the application comes to the forefront:
NSDictionary *userInfo = remoteMessage.appData; UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.userInfo = userInfo; localNotification.soundName = UILocalNotificationDefaultSoundName; localNotification.alertBody = userInfo[@"yourBodyKey"]; localNotification.alertTitle = userInfo[@"yourTitleKey"]; localNotification.fireDate = [NSDate date]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
It will launch a notification at the very moment when the application appears in the foreground.