Firebase sending multiple push notifications inste

2019-02-17 13:54发布

问题:

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

回答1:

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