Sending notification via GCM

$msg = array( 'title' => 'This is a title. title', 'message' => 'here is a message. message', ); $fields = array( 'registration_ids' => $r, 'data' => $msg, ); $headers = array( 'Authorization: key=' . $gcm_auth_key, 'Content-Type: application/json', ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); curl_close($ch); 

Everything is sent successfully, I accept the message in the service worker for example https://developer.mozilla.org/ru/docs/Web/API/PushEvent

 self.addEventListener('push', function(event) { console.log(event); }); 

The problem is that in the example the data is taken from event.data and I get event.data = null

What could be the reason and how to get the message text inside self.addEventListener ('push'

thank

    1 answer 1

    GCM does not yet support payload with notification. Mozilla yes, Google Cloud Messaging - no.

    you can't send any data with a push message. Nope, nothing.

    from here

    • thanks, tell me how to implement a show from self.addEventListener ('push', function (event) {I make a request for a php script in which I have an array with several push notifications, they seemed, one more entry is added over time, and push again, it shows everything that was new, how can this be avoided, or should only actual records be displayed? - Dmitry Nagulin
    • The link shows everything, and this moment too: when receiving a notification, your Web Worker should request data from the server, or prepare it himself, and only after the data is ready to show a notification with this data. - Sergiks 2:01 pm