0
votes

I use react native push notification with firebase cloud messaging to handle receiving push. My problem is i can't receive the push in foreground.

My code is :

 // Receive displayed notifications for iOS 10 devices.
// Handle incoming notification messages while app is in the foreground.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  NSDictionary *userInfo = notification.request.content.userInfo;

  // With swizzling disabled you must let Messaging know about the message, for Analytics
  [[FIRMessaging messaging] appDidReceiveMessage:userInfo];

  // Print message ID.
  if (userInfo[kGCMMessageIDKey]) {
    NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  }

  // Print full message.
  NSLog(@"%@", userInfo);

  // Change this to your preferred presentation option
  completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
}
2

2 Answers

0
votes

https://medium.com/@anum.amin/react-native-integrating-push-notifications-using-fcm-349fff071591

This link will help you, sir.

hello, this tutorial works in this issue, especially in

import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;

the RNFirebaseNotificationsPackage, we have encountered the same issue and have fixed it by adding the package :)

0
votes

In FCM, the notification is not showing if you are already foreground.

You have handle 3 different case for push notification.

  1. Foreground
  2. Background
  3. Exit(app is not running)

In case 2, 3 you seems to handle correctly. In case 1 you have to show your push notification manually in local.