Firebase发送多个推送通知而不是堆叠或替换。

5
我正在尝试在Android系统托盘中使用新的推送通知栈来替换之前的推送通知或与之合并。
由于推送通知同时发送数据和通知对象,我不确定如何实现这一点。据我所知,通知直接进入系统托盘。那么,如何阻止独立出现的通知?有些用户会收到5-10个通知,它们会不断上升。
编辑: 我尝试了collapse_key,但仍无法用相同的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

我正在尝试添加“collapse_key”:“follow”,但它仍然显示为新消息。 - Lion789
@frankvanpuffelen,我已经添加了我的消息,请告诉我是否搞砸了什么。 - Lion789
没有任何区别,但是谷歌说这并不重要,他们会进行适当的重定向。 - Lion789
你找到解决方案了吗?我的“collapse_key”似乎也没有效果。 - grantespo
现在也是collapseKey吗?https://firebase.google.com/docs/reference/admin/node/admin.messaging.MessagingOptions.html#collapsekey - behelit
显示剩余2条评论
1个回答

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'
                                    }
                                };

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接