![](/img/trans.png)
[英]How can I send a firebase cloud messaging notification from javascript?
[英]How do I give my Firebase Cloud Messaging notification a tag property?
我正在嘗試按照此處和此處所述在 Android 上為我的 Firebase 雲消息傳遞通知提供標簽屬性,以便我可以在必要時替換已收到的通知。
我正在使用 React Native、 React Native Firebase和 ConnectyCube API。 ConnectyCube 與 Firebase 一起處理用戶管理和推送通知- 我有所有這些工作。
我無法弄清楚如何格式化我的有效負載對象以包含可選屬性,例如tag
因為文檔相當神秘。 我成功發送了一條message
,該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
是 Notification 類型推送的有效負載鍵,但 ConnectyCube 將所有推送作為數據發送。
使用數據推送可以完全控制如何處理通知(顯示或不顯示),因此有一種方法可以在應用程序中添加代碼以隱藏現有通知,然后在收到數據推送后顯示新通知
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.