【发布时间】:2020-11-25 23:29:32
【问题描述】:
我尝试像android group notification 和ios group notification 那样实现群组通知。但我做不到。我也试过这个flutter_local_notification 插件。但这仅在应用打开时有效。不在前台(onResume)和后台工作。
void registerNotification() {
_fcm.configure(
onMessage: (Map<String, dynamic> message) {
return;
},
onResume: (Map<String, dynamic> message) {
return;
},
onLaunch: (Map<String, dynamic> message) {
return;
},
onBackgroundMessage: backgroundMessageHandler);
}
有效载荷
const payload = {
notification: {
title: title,
body: message,
},
data: {
click_action: "FLUTTER_NOTIFICATION_CLICK",
sound: "default"
},
android: {
priority: "high",
collapse_key: userName,//tried to add collapse_key for group notification
},
apns: {
headers: {
"apns-priority": "5",
},
},
token:token,
};
解决方案
我看到了 react-native 的答案,你必须使用 Flutter 和 firebase_messaging react native answer 做同样的事情
【问题讨论】:
-
嘿。从你的评论到这里。我对颤振不太熟悉,但从你链接的 RN 答案看来,
.android.setGroup(ALERTS_GROUP)存在——我认为这是你正在使用的那个?您提到它仅在应用程序打开时才有效,这可能是基于有效负载内容。我建议尝试仅使用notification发送有效负载,仅使用data发送有效负载(保留其他配置)并查看行为是否发生变化。干杯! -
是否可以使用 fcm 有效负载创建分组通知?我看到了这个例子。 (groupKey 在这里)distriqt.github.io/ANE-PushNotifications/m.FCM-GCM%20Payload 但是当前 fcm 有效载荷上没有密钥(groupKey)。不是吗?
-
FCM 中没有原生
groupKey。当您查看示例时,所有项目都在data内(即data: { notification: { ... } }),这意味着其中的所有内容都是自定义键值 - 开发人员也可以按照他们想要的方式接收和处理。 -
好的@AL。当应用程序在后台(应用程序未打开)时,我需要使用组通知。这意味着应用程序需要在后台运行。不是吗?再次感谢您的支持。对不起我的英语不好
-
不用担心。我不知道颤振,但对于 Android,你只需要扩展 FirebaseMessagingService ,它通常会在后台运行。之后,您需要重写接收到有效负载时触发的函数——我快速扫描了一些页面,它的对应部分似乎是
backgroundMessageHandler。从这里,获取data并解析每个并根据需要设置组。那应该差不多了。祝你好运。干杯!
标签: firebase flutter firebase-cloud-messaging