是否可以在 Flutter 中使用 FCM 实现通知分组/捆绑?

Blo*_*oss 6 firebase flutter firebase-cloud-messaging

我尝试实现这样的组通知android group notificationios 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);
  }
Run Code Online (Sandbox Code Playgroud)

有效载荷

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,
};
Run Code Online (Sandbox Code Playgroud)

解决方案

我看到了对此的 react-native 答案,您必须使用 Flutter 和react native 答案做同样的事情firebase_messaging

小智 -1

如果你想提交一个组,你需要订阅一个主题,在提到它的文档中,你将不再发送单个令牌,而是订阅一个主题并将其提交到该主题。

  • 否 否,如果“A”用户向“B”用户发送多条消息。目前,我的通知面板中有很多通知,我想为此对通知进行分组。(这意味着像上图一样 gmail/whatsapp)。如果“C”用户向“B 用户”发送了多条消息。我想要 2 组..抱歉我的英语不好:) (2认同)
  • 主题用于大规模发送给多个用途的组。根据这个问题,@BloodLoss 似乎是在询问如何将通知捆绑/分组到一个通知项目下,而不是一种发送通知的方式。 (2认同)