Firebase发送多个推送通知,而不是堆叠或替换 [英] Firebase sending multiple push notifications instead of stacking or replacing
问题描述
我不确定如何做到这一点因为推送通知正在发回数据和通知对象,并且据我所知,通知直接发送到系统托盘。如果是这样,我该如何阻止通知独立出现。有些用户会得到5-10个通知,并会继续推动。
编辑:
我试过了collapse_key但它仍然不会取代之前的通知使用相同的密钥...我在这里做错了什么?
方法:' POST',
uri:'https://gcm-http.googleapis.com/gcm/send',
标题:{
'Content-Type':'application / json',
'Authorization':authorize // GOOGLE API KEY
},
body:JSON.stringify({
registration_ids:[otherUserResult.reg_id],
collapse_key:follow,
data:{
notifyToUserId:to,
notifyFromId:fr om,
notifyMsg:msg,
notifyItemPicture:itemPic,
notifyItemName:itemName,
notifyFromName:fromName,
notifyType:类型,
dateNotified:dateNotified
},
通知:{
title:fromName,
body :通知管理,
icon:ic_pushnotify
},
priority:high,
content_available:true
b
$ b
collapse_key:'your_app_unique_string',
tag:'your_app_unique_string'
所以完整的代码是:
$ $ $ $ $ $ $ $ $ $ $ $ b title:Mensaje de+ message.name,
body:message.text,
sound:default,
collapse_key:'charlero',
tag:'charlero '
}
};
I am trying to have a previous push notification stack with the new one or replace it in the system tray for android.
I am not sure how to do this as the push notification is sending back both data and notification objects, and from what I understand the notification goes directly to the system tray. If so how do I stop the notification from appearing independently. Some users would get 5-10 notifications and it would keep pushing up.
EDIT:
I tried collapse_key but it still does not replace prior notifications with the same key... am I doing it wrong somehow here?
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
For me worked when I included in my 'notification' 2 lines:
collapse_key: 'your_app_unique_string',
tag: 'your_app_unique_string'
So the full code would be:
var payload = {notification: {
title: "Mensaje de "+message.name,
body: message.text,
sound: "default",
collapse_key: 'charlero',
tag: 'charlero'
}
};
这篇关于Firebase发送多个推送通知,而不是堆叠或替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!