How to collapse multiple notifications into a single one using Firebase?(如何使用 Firebase 将多个通知合并为一个?)
问题描述
我在 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 将多个通知合并为一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Firebase 将多个通知合并为一个?
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
