invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.69k stars 2.21k forks source link

Two notifications receiving(one without data and another local notification) When App is in Background Or Kill State #6568

Closed ZaidQ797 closed 2 years ago

ZaidQ797 commented 2 years ago

Hi folks I'm using notifee with Firebase Messaging in react native project.When I send notification from FMC I receive only one notification that is good but When notification is sent from my server and app is in background or Killed state I receive Two notifications the first one contains nothing just empty notification and another notification is that I'm displaying with notifee as notifee.displayNotification({title:'Title',body:'Body'}).

useEffect(() => {
    const unsubscribe = messaging().onMessage(async remoteMessage => {
      const { data } = remoteMessage;
      let payload = eval('({' + data?.payload + '})');
      await notifee.displayNotification({
        title: data?.title,
        body: data?.body,
      });
 });
    return unsubscribe;
  }, []);

And I'm setting background Handler in index.js like this messaging().setBackgroundMessageHandler(async remoteMessage => {}) I tried to add display notification code in Background Handler as well but if I left empty or add displayNotification code both cases receiving two notifications.

mikehardy commented 2 years ago

Why are you double-posting? Don't do that please. Closing as duplicate https://github.com/invertase/notifee/issues/524

ansarsufiyana commented 2 months ago

hi am facing the same issue. I have changed the payload.notification to payload.data . it works fine when I receive a notification from my backend. now when I hit notification from the Firebase console I receive two notifications one with my notification message and one with empty. I have handled my front end accordingly to both payloads. I am using Firebase in my next JS project. anyone with this issue or solution please get in touch with me .