在 iOS 上使用 Firebase 消息将多个推送通知合并/折叠为 1

时间:2020-12-27 11:57:18

标签: firebase firebase-cloud-messaging apple-push-notifications firebase-admin

我正在使用 Firebase Cloud Functions 发送推送通知。我想将多个推送通知折叠/合并为 1。我知道如果设备处于离线状态并且使用相同的 collapseKey 发送多个推送通知,它们将合并为 1。但我希望合并用户是否在线/离线。

我已经想出了如何使用 Android 执行此操作(在下面的 tag 对象中使用 notification 属性)。我知道有 apns-collapse-id 但我不知道它属于哪里。我已经阅读并尝试了几个不同的 StackOverflow 帖子,但到目前为止没有任何效果。

来自我的 Cloud Functions 代码的片段:

const notification = {
    "notification":{
        "title":"Woohoo!",
        "body":"New push notification!",
        "tag": "collapse_id",   // Works on Android
    },
    "apns": {
        "headers": {
            "apns-collapse-id": "collapse_id",  // Does not work on iOS
        }
    },
    "token": "tokenGeneratedUsingFCM",
};

await admin.messaging().send(notification).then(_ => {
    console.log(`Successfully sent message`);
    return;
    })
    .catch(error => {
    console.log(`Error sending message: ${error}`);
    });

我正在使用 firebase_admin v9.4.2(这是上面的 admin 变量的来源)。

0 个答案:

没有答案