D
D
dimon1192016-06-02 11:07:10
Push technologies
dimon119, 2016-06-02 11:07:10

Why is event.data null when sending a push notification?

Send 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,
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);

Everything is successfully sent, I receive a message in the service worker according to the example https://developer.mozilla.org/en/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'
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2016-10-19
@mututunus

The data must be encrypted.
https://developers.google.com/web/updates/2016/03/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question