phonegap-plugin-push using data payload only replaces existing notification

167 Views Asked by At

I am using phonegap-plugin-push with Ionic3.

In the plugin-push documentation

they are saying that on Android device we should use only data payload and not the notification in order the on('notification') will be triggered.

So far so good, but sending only the data payload, causing the notification tray to replace/overrides existing notification previously sent.

When sending notification payload, a new notification enters the notification tray without replacing existing one, but on tap event not triggered.

How can I achive both behaviors?

My payload:

{
   "message":{

      "android":
      {
         "data":{

            "title":"Hello",
            "body":"Hello",
            "timestamp":"2018-12-20T09:56:55.3250752+02:00"
         }
      },
      "apns":{
         "payload":{
            "aps":{
               "alert":{
                  "title":"Hello",
                  "body":"Hello",
                  "timestamp":"2018-12-20T09:56:55.3250752+02:00"
               }
            }
         }
      },
      "token": "f9j....."
   }
}
1

There are 1 best solutions below

0
Nir-Z On

using a unique notId property in data payload solved the problem

{
   "message":{

      "android":
      {
         "data":{
            "title":"Hello",
            "body":"Hello",
            "notId": "1646269",
            "timestamp":"2018-12-20T09:56:55.3250752+02:00"
         }
      },
      "apns":{
         "payload":{
            "aps":{
               "alert":{
                  "title":"Hello",
                  "body":"Hello",
                  "timestamp":"2018-12-20T09:56:55.3250752+02:00"
               }
            }
         }
      },
      "condition": "'topic.test' in topics"
   }
}