5

我正嘗試使用新的推送通知堆棧或將其替換爲系統托盤中的android。Firebase發送多個推送通知,而不是堆疊或替換

我不知道如何做到這一點,因爲推送通知正在發回數據和通知對象,並從我所瞭解的通知直接到系統托盤。如果是這樣,我該如何阻止通知獨立出現。一些用戶會得到5-10個通知,並且會繼續增加。

編輯:

我試圖collapse_key的,但它仍然沒有使用相同的密鑰更換之前通知...我做錯了不知何故在這裏嗎?

method: 'POST', 
          uri: 'https://gcm-http.googleapis.com/gcm/send', 
          headers: { 
           'Content-Type': 'application/json', 
           'Authorization': authorize //GOOGLE API KEY 
          }, 

          body: JSON.stringify({ 
           "registration_ids": [otherUserResult.reg_id], 

           "collapse_key": "follow", 
           "data": { 
            "notifyToUserId": to, 
            "notifyFromId": from, 
            "notifyMsg": msg, 
            "notifyItemPicture": itemPic, 
            "notifyItemName": itemName, 
            "notifyFromName": fromName, 
            "notifyType": type, 
            "dateNotified": dateNotified 


           }, 
           "notification": { 
            "title": fromName, 
            "body": notifyMsg, 
            "icon" : "ic_pushnotify" 
           }, 
           "priority": "high", 
           "content_available": true 
+0

你在尋找什麼所謂的可摺疊消息。請參閱https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages –

+0

我嘗試添加「collapse_key」:「follow」,但它仍顯示爲新消息 – Lion789

+0

@frankvanpuffelen I添加我的消息,讓我知道如果我搞砸了 – Lion789

回答

0

爲我工作,當我包含在我的「通知」 2號線:

collapse_key: 'your_app_unique_string', 
tag: 'your_app_unique_string' 

所以完整的代碼是:

var payload = {notification: { 
             title: "Mensaje de "+message.name, 
             body: message.text, 
             sound: "default", 
             collapse_key: 'charlero', 
             tag: 'charlero' 
            } 
           };