Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications show duplicates in background state #1173

Open
baronha opened this issue Dec 18, 2024 · 3 comments
Open

Notifications show duplicates in background state #1173

baronha opened this issue Dec 18, 2024 · 3 comments

Comments

@baronha
Copy link

baronha commented Dec 18, 2024

I saw this issue #690, #767 and I don't know how to completely solve the above problem when displaying notification from Firebase's setBackgroundMessageHandler. How is this resolved in version 7.0.0+ on notifee?
Before that I was still able to use firebase's onNotificationOpenedApp api and it worked fine.
https://rnfirebase.io/messaging/usage#background--quit-state-messages

My code:

messaging().setBackgroundMessageHandler(
  async (remoteMessage) => await onDisplayNotification(remoteMessage)
);
const onDisplayNotification = async (remoteMessage) => {
  const payload = remoteMessage?.notification;
  const title = payload?.title;
  if (!title) return;

  await notifee.createChannel({
    id: "default",
    name: "ELearning Channel",
    sound: "noti",
    vibration: true,
    importance: AndroidImportance.HIGH,
  });

  await notifee.displayNotification({
    title,
    body: payload?.body ?? "Có một thông báo mới",
    data: remoteMessage?.data,
    android: {
      channelId: "default",
      sound: "noti",
      // importance: AndroidImportance.HIGH,
      category: AndroidCategory.MESSAGE,
      visibility: AndroidVisibility.PUBLIC,
      smallIcon: "notification_icon",
      circularLargeIcon: true,
      largeIcon: 'notification_icon',

      pressAction: {
        launchActivity: "default",
        id: "default",
      },
    },
    ios: {
      // ...
    },
  });
};

Result

Screenshot 2024-12-18 at 14 18 59

@ketanuengage
Copy link

@baronha Its happening for me as well but only in iOS. Did you find any solution?

@sbaiahmed1
Copy link

+1

@pavelustenko
Copy link

In my experience, there was a case where I sent a notification object along with data. So one notification was created by Android automatically, and the second was created by setBackgroundMessageHandler. So I switched to data-only notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants