首页 > 解决方案 > FCM 不会堆叠类似的消息?

问题描述

我正在尝试堆叠类似的消息,而不是为每条相同的消息发送单独的通知。

下面是我的代码

 const payload = {
      notification: {
        title: `added new report`,
        body: change.after.data().report_title,
        tag: "ReportLog",
      },
      data: {
        click_action: "FLUTTER_NOTIFICATION_CLICK",
        sound: "default",
        status: "done",
      },
    };

    const options = {
      priority: "high",
      collapseKey: "ReportLog",
    };

await admin.messaging().sendToDevice(tokens, payload, options);

所以假设我一次又一次地发送相同的消息,而不是堆叠消息,旧通知被新通知替换

标签: androidfirebasegoogle-cloud-functionsfirebase-cloud-messaging

解决方案


On the server side you can "remember" the last notify and don't send another. (Bad idea)

On the client you can do the same. (Also bad idea) But the thing is, that the "remember" logic won't work if the app is the background, because the notify will be handled by the system and not by your logic in the app.


推荐阅读