invertase / notifee

⚛️ A feature rich notifications library for React Native.
https://notifee.app
Apache License 2.0
1.81k stars 213 forks source link

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

Closed ZaidQ797 closed 1 year ago

ZaidQ797 commented 1 year 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 1 year ago

Hi there, we'll need

it may be that your payload is not what you think it is so the title/body are empty, generating the empty notification? I'm unaware of any firebase SDK behavior that will generate an empty notification for you so I can only speculate without seeing the JSON FCM that will trigger this

https://stackoverflow.com/help/how-to-ask

It would be best to condense this to a single index.js as a reproduction (https://stackoverflow.com/help/minimal-reproducible-example)

You can format your code nicely with triple-backticks and a language designator (like javascript) so it's more readable

I'm surprised you display a second notification in the background/quit state, as you have not specified any background message handler logic, so you have no code running there. I suspect you have omitted some necessary steps in the reproduction steps like for example "when I tap on the notification..."

ZaidQ797 commented 1 year ago

It was header issue on backend and its fixed from backend

yasircodingcrafts commented 1 year ago

Hi @ZaidQ797 I am facing the same issue. Can you let me know which header was causing the issue?

ZaidQ797 commented 1 year ago

Hi @ZaidQ797 I am facing the same issue. Can you let me know which header was causing the issue?

its on backend side.You can check the apns and alert type in this article. https://firebase.google.com/docs/cloud-messaging/send-message

windcloudit commented 1 year ago

I also facing same issue, @ZaidQ797, could you tell me more detail?

Jamal-ReachFirst commented 1 year ago

facing the same issue, one notification is displayed by notifee.display() and another one firebase with default properties, reopen this

Jamal-ReachFirst commented 1 year ago

Sending data only notifications fixed the issue for me

fukemy commented 6 months ago

Sending data only notifications fixed the issue for me

that bad solution, server always need to send notification content, no only data

neilanthonyte commented 1 month ago

Hi, any solution on this? So this is what I encounter.

No notification property from the backend - this fixes the issue if the app is in foreground/minimized app but failed when the app is totally closed/quit . . without the notification property the notification will not work when the app is in kill mode.

With notification property from the backend - this fixes the issue when the app is in kill mode, but there are two notifications received . . one is the default firebase and 2 is the notifee display

is there a way to override the firebase?