Firebase 发送多个推送通知而不是堆叠或替换 [英] Firebase sending multiple push notifications instead of stacking or replacing

查看:52
本文介绍了Firebase 发送多个推送通知而不是堆叠或替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的推送通知堆栈或将其替换为 android 系统托盘中的先前推送通知堆栈.

I am trying to have a previous push notification stack with the new one or replace it in the system tray for android.

我不确定如何执行此操作,因为推送通知会同时发回数据和通知对象,据我所知,通知直接发送到系统托盘.如果是这样,我如何阻止通知独立出现.一些用户会收到 5 到 10 条通知,并且会不断推送.

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.

我尝试了 collapse_key 但它仍然没有用相同的键替换之前的通知......我在这里做错了吗?

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

推荐答案

对于我来说,当我在我的通知"中包含 2 行时工作:

For me worked when I included in my 'notification' 2 lines:

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

这篇关于Firebase 发送多个推送通知而不是堆叠或替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆