gpt4 book ai didi

ios - 如何在 FCM 中使用 apns-collapse-id?

转载 作者:行者123 更新时间:2023-12-03 11:17:02 24 4
gpt4 key购买 nike

我知道这个问题已经被问过很多次了,但没有一个答案对我有用。有些问题甚至没有答案。

我尝试在 ios 上捆绑或分组类似的通知。我正在使用 FCM Cloud Functions 来触发通知。

以下是我尝试过的方法

const payload = {
notification: {
title: "Your medical history is updated" + Math.random(),
tag: "MedicalHistory",
},
data: {
click_action: "FLUTTER_NOTIFICATION_CLICK",
sound: "default",
status: "done",
},
};

const patchedPayload = Object.assign({}, payload, {
apns: {
headers: {
"apns-collapse-id": "MedicalHistory",
},
},
});

const options = {
priority: "high",
collapseKey: "MedicalHistory",
};


await admin
.messaging()
.sendToDevice("MY_TOKEN", patchedPayload, options);

上面的代码不起作用
const payload = {
notification: {
title: "Your medical history is updated" + Math.random(),
tag: "MedicalHistory",
},
data: {
click_action: "FLUTTER_NOTIFICATION_CLICK",
sound: "default",
status: "done",
},
apns: {
headers: {
"apns-collapse-id": "MedicalHistory",
},
},
};



const options = {
priority: "high",
collapseKey: "MedicalHistory",
};

await admin
.messaging()
.sendToDevice("MY_TOKEN", payload, options);

这也行不通。

我不明白把 apns-collapse-id 放在哪里.云函数示例也没有显示这一点。我也找不到带有代码的文档

最佳答案

我建议使用最新的 send来自 firebase-admin 的函数lib,用法描述 here .
它似乎工作得很好,而且更容易应用。
带有 android/ios 特定 header 的消息示例:

// common data for both platforms
const notification = {
title: 'You liked!',
body: 'You really liked something...',
}
const fcmToken = '...'

// android specific headers
const android = {
collapseKey: '0'
}

// ios specific headers
const apns = {
headers: {
"apns-collapse-id": '0'
}
}

// final message
const message = {
token: fcmToken,
notification: notification,
android: android,
apns: apns,
}

// send message
admin.messaging().send(message).catch(err => console.error(err));

关于ios - 如何在 FCM 中使用 apns-collapse-id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61119466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com