如何使用Firebase将多个通知折叠为一个通知? [英] How to collapse multiple notifications into a single one using Firebase?

查看:141
本文介绍了如何使用Firebase将多个通知折叠为一个通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firebase Cloud Functions中具有功能,该功能用于向我的应用程序内的特定用户发送通知,并且具有以下代码作为notificationContent:

I have function in Firebase Cloud Functions which is used to send notifications to specific users within my app and has as the notificationContent the following code:

const notificationContent = {
    notification: {
        title: "My Notification Title",
        body: "My Notification Body",
        icon: "default",
        sound : "default"
    }
};

我尝试使用collapse_key: "unique_key",但没有效果.我阅读的内容仅在设备离线时才有效.我还使用了tag: "unique",但是每次收到新通知时,它将覆盖最旧的通知.

I have tried to use collapse_key: "unique_key" but it has no effect. I read the has an effect only when the device is offline. I also have used a tag: "unique" but every time a new notification arrives, it will override the oldest one.

我有什么方法可以使用Firebase做到这一点?如果我收到的通知多于一个,可以分为一个通知吗?

I there any way in which I can achieve this with Firebase? If I receive more then one notification, to be grouped in a single one?

提前谢谢!

推荐答案

如果要使用更多可定制和高级的通知功能. 您只应发送带有data有效负载的FCM,并在android客户端创建通知.
请记住,如果您发送带有notification有效负载或notification + data有效负载的FCM,则通知将由android核心系统创建,并且如果您的应用程序处于打开状态,则不会调用BroadcastReceiveronReceive方法背景.
如果您发送带有data有效负载的FCM,它将一直调用onReceive,因此您可以在android客户端手动生成自定义通知. (大多数应用使用后一种方法.)

If you want to use more customizable and advanced notification features. You should only send FCM with data payload, and create notification at android client side.
Remember that if you send FCM with notification payload or notification + data payload, the notification will be created by android core system and BroadcastReceiver's onReceive method won't being called if your app is on background.
If you send FCM with data payload, it will call onReceive all the time, so you can produce custom notification manually at android client side. (most app uses latter method.)

我希望此链接会有所帮助.

这篇关于如何使用Firebase将多个通知折叠为一个通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆