我正在尝试为我的 Firebase 云消息通知提供 Android 上的标记属性,如所述 here和 here这样我就可以在必要时替换已收到的通知。
我正在使用 React Native,React Native Firebase和 ConnectyCube API。 ConnectyCube 与 Firebase 配合处理用户管理和 push notifications - 我已经完成了所有这些工作。
我不知道如何格式化我的有效负载对象以包含可选属性,例如tag
,因为文档相当神秘。我成功发送了一条包含在 message
属性中的 message
,并且在 ConnectyCube 文档中,您将看到 badge
的 iOS 可选属性只是 payload
对象中的另一个属性,但对于 Android 的 tag
来说,以下代码不起作用:
export const sendNotification = async (calleeId, callLength, tagUUID) => {
const callersUserName = await getUserNameFromStorage();
const payload = JSON.stringify({
message: callersUserName + '-' + callLength,
tag: tagUUID,
});
const pushParameters = {
notification_type: 'push',
user: { ids: [calleeId] }, // recipients.
environment: 'production', // environment, can be 'production'.
message: ConnectyCube.pushnotifications.base64Encode(payload)
};
ConnectyCube.pushnotifications.events.create(pushParameters, function (error, result) {
});
setTimeout(() => {
const payload2 = JSON.stringify({
message: 'replacement-notification',
tag: tagUUID,
});
const pushParameters2 = {
notification_type: 'push',
user: { ids: [calleeId] }, // recipients.
environment: 'production', // environment, can be 'production'.
message: ConnectyCube.pushnotifications.base64Encode(payload2)
};
ConnectyCube.pushnotifications.events.create(pushParameters2, function (error, result) {
});
}, 3000)
}
当推送通知具有相同的标签时,每个通知都将被替换为我试图用 setTimeout
模仿的新通知。
我收到了两条消息,但第一条消息没有被第二条消息替换!
非常感谢任何帮助! :)
最佳答案
tag
是通知类型推送的有效负载键,但 ConnectyCube 将所有推送作为数据发送。
通过数据推送,可以完全控制如何处理通知(显示或不显示),因此有一种方法可以在应用程序中添加代码来隐藏现有通知,然后在数据发送后显示新通知收到推送
关于javascript - 如何为我的 Firebase Cloud Messaging 通知提供标签属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59750627/