我在 Firebase Cloud Functions 中有一个函数,用于向我的应用程序中的特定用户发送通知,并且具有以下代码:
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 核心系统和 BroadcastReceiver 创建如果您的应用处于后台,则不会调用
的 onReceive
方法.
如果您发送带有 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 将多个通知合并为一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!