【问题标题】:why firebase cloud messaging notification for web duplicate notifications为什么针对网络重复通知的 Firebase 云消息通知
【发布时间】:2022-11-10 14:36:09
【问题描述】:

我正在制作一个具有通知功能的网络应用程序。但是我收到的消息被重复了。
第一个没有图像。但第二条消息有图片,标题是${notificationTitle}123

// Scripts for firebase and firebase messaging
importScripts('https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging-compat.js');

// Initialize the Firebase app in the service worker by passing the generated config
const firebaseConfig = {
  // ...api key
}

firebase.initializeApp(firebaseConfig);

// Retrieve firebase messaging
const messaging = firebase.messaging();

messaging.onBackgroundMessage(function(payload) {
  console.log('Received background message ', payload);

  const notificationTitle = payload.notification.title;
  const notificationOptions = {
    body: payload.notification.body,
    image: payload.notification.image,
    icon: payload.notification.image,
  };

  self.registration.showNotification(`${notificationTitle}123`, notificationOptions);
});

【问题讨论】:

    标签: firebase frontend service-worker


    【解决方案1】:

    我面临同样的问题。 你找到解决办法了吗?请让我知道你是否有,因为我在我的项目中遇到了这个错误。我正在使用 firebase 云消息传递仪表板推送通知并接收重复通知。 先感谢您。

    【讨论】:

      猜你喜欢
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      • 2017-12-24
      相关资源
      最近更新 更多