Closed mrpotensial closed 3 years ago
Can you share your Service Worker code?
im still using serviceworker code from here
const sendNotification = body => {
// you could refresh a notification badge here with postMessage API
const title = "Web Push example";
return self.registration.showNotification(title, {
body,
});
};
Your body object should contain the following properties
{
"//": "Visual Options",
"body": "<String> body.msg (in your case)",
"icon": "<URL String>",
"image": "<URL String>",
"badge": "<URL String>",
"vibrate": "<Array of Integers>",
"sound": "<URL String>",
"dir": "<String of 'auto' | 'ltr' | 'rtl'>",
"//": "Behavioral Options",
"tag": "<String>",
"data": "<Anything>",
"requireInteraction": "<boolean>",
"renotify": "<Boolean>",
"silent": "<Boolean>",
"//": "Both visual & behavioral options",
"actions": "<Array of Strings>",
"//": "Information Option. No visual affect.",
"timestamp": "<Long>"
}
im solving this with converting data in body to array, so my service worker code become like this,
const sendNotification = body => { const title = "Title Here"; var option2 = JSON.parse(body); return self.registration.showNotification(title, option2); };
sorry if i do this wrong, first time creating issue
Setup
Problem
Expected
i can change the content of notification by changing the serviceworker, but cant change it dynamicly based on payload
Features Used
Example / Reproduce Case
Other
im already using json_encode to my array before using them in payload, but stil didnt work, so my code become like this
$report = $webPush->sendOneNotification( $subscription, '{"title":"hello","msg":"yes it works"}' );