Reputation: 443
i am using php web push to send notification
here is php code
$notifContent888 = array(
'title' => 'test tiltle',
'body' => 'This is the body content',
'icon' => 'https://png.pngtree.com/element_origin_min_pic/16/08/05/1057a3fae73b91b.jpg',
);
$pay_load9988=json_encode($notifContent888);
$subscription_new = Subscription::create([
'endpoint' => $endpoint,
'publicKey' => $publicKey_99,
'authToken' => $authToken,
'contentEncoding' => $contentEncoding,
]);
$webPush = new WebPush($auth);
$webPush->sendNotification($subscription_new, $pay_load9988, true);
here is service worker js part
if (event.data) {
var payload = event.data.json();
var title = payload.title;
var body = payload.body;
var icon = payload.icon;
console.log(payload);
event.waitUntil(sendNotification(title, {
body: body,
icon: icon,
data: {}
}
I can see that in console.log all data came nicely but i get notification only with default title and body and icons are not displayed. i can see body and icons in console and if i replace title with body i can see body content but i dont know what is happening only one part i am able to send notification through payload only first part whatever i mention just after sendNotification(title
here only title will come
any help in finding out mistake will be great. is this encryption issue of payload??
Upvotes: 0
Views: 631
Reputation: 1917
When using sendNotification
you don't need to encrypt the data since sendNotification
does it already for you. See: https://www.npmjs.com/package/web-push
So you should change your code like this:
$notifContent888 = array(
'title' => 'test tiltle',
'body' => 'This is the body content',
'icon' => 'https://png.pngtree.com/element_origin_min_pic/16/08/05/1057a3fae73b91b.jpg',
);
$subscription_new = Subscription::create([
'endpoint' => $endpoint,
'publicKey' => $publicKey_99,
'authToken' => $authToken,
'contentEncoding' => $contentEncoding,
]);
$webPush = new WebPush($auth);
$webPush->sendNotification($subscription_new, $notifContent888, true);
Upvotes: 0