使用离子推送的多次推送通知

时间:2016-04-02 13:17:29

标签: android ionic-framework push-notification google-cloud-messaging firebase-cloud-messaging

发送两个通知时,第二个通知会覆盖通知中心的第一个通知。 根据{{​​3}},只有在使用标记时才会发生这种情况:

  

" tag":表示每条通知消息是否产生新消息   进入通知中心。如果未设置,则每个请求都会创建一个   新通知。如果设置,则具有相同标记的通知为   已经显示,新通知取代现有通知。

然而,无论我是否为标签设置了值,这都会发生在我身上。

我甚至尝试过设置随机标签& collapse_key(据我所知,在这种情况下我不应该相关,但我试了一下)。仍然没有帮助。 这是我发送的通知对象示例:

{  
   "tokens":[  
      "my-device-token"
   ],
   "profile":"my-profile-tag",
   "notification":{  
      "message":"message",
      "android":{  
         "payload":{  
            "collapse_key":9918519,
            "tag":2825928
         }
      }
   }
}

2 个答案:

答案 0 :(得分:5)

我解决了这个问题。 你需要添加" notId"进入"数据" in" android"。 例如:

"notification": {
    "title": "testing stack notification ",
    "message":"is it working",
    "android": {               
        "data": {
            "title": "testing stack notification",
            "message": "is it working",
            "style": "inbox",
            "summaryText": "yes its %n% notifications",
            "notId": "123456"
        }
    }
}

答案 1 :(得分:0)

您需要在对象中指定唯一的通知ID(例如unix时间戳),以便不覆盖前一个 - 在您的情况下:

{  
   "tokens":[  
      "my-device-token"
   ],
   "profile":"my-profile-tag",
   "notification":{  
      "notId": <some-unique-value-here>,
      "message":"message",
      "android":{  
         "payload":{  
            "collapse_key":9918519,
            "tag":2825928
         }
      }
   }
}