使用 firebase_messaging 包更新现有通知时,无法在 iOS 上的 rMessage (RemoteMessage) 中获取 CollapseKey

问题描述 投票:0回答:1

我正在将以下有效负载发送到 FCM API

{
  message: {
    token: DEVICE_TOKEN,
    apns: {
      headers: {
        'apns-priority': '5',
        'apns-push-type': 'alert',
        'apns-collapse-id': '113',
      },
      payload: {
        aps: {
          alert: {
            title: 'Brand new title',
            body: 'Brand new text',
          },
          category: 'XYZ_CATEGORY',
        },
      },
    },
  },
}

我在任何类之外编写了以下后台远程通知处理程序,作为我的 Flutter 应用程序中的顶级函数:

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage rMessage) async {
  await Firebase.initializeApp();
  debugPrint('Handling a background message ${rMessage.toMap()}');
}

这是控制台中的输出,其中

collapseKey
为空。

{
  senderId: null,
  category: 'XYZ_CATEGORY',
  collapseKey: null,
  contentAvailable: true,
  data: {},
  from: null,
  messageId: 1706272050712326,
  messageType: null,
  mutableContent: false,
  notification: {
    title: 'Brand new title',
    titleLocArgs: [],
    titleLocKey: null,
    body: 'Brand new text',
    bodyLocArgs: [],
    bodyLocKey: null,
    android: null,
    apple: {
      badge: null,
      subtitle: null,
      subtitleLocArgs: [],
      subtitleLocKey: null,
      imageUrl: null,
      sound: null,
    },
    web: null,
  },
  sentTime: null,
  threadId: null,
  ttl: null,
}

apns-collapse-id
未映射到
collapseKey

我的问题:

  1. 如果我没有获得collapseKey,如何替换现有的通知?
  2. 我的要求有遗漏吗?
ios flutter firebase-cloud-messaging apple-push-notifications
1个回答
0
投票

collapseKey
仅适用于Android。
apns-collapse-id
不会映射到 Firebase 中的此属性。

根据我的观察,替换通知不必手动完成。如果您发送带有

apns-collapse-id
的远程通知为
1
,然后发送具有相同 id 的以下远程通知,iOS 会处理用新通知替换旧通知。

© www.soinside.com 2019 - 2024. All rights reserved.