Moved firebase messaging notification handling to messaging generation.

This commit is contained in:
Patrick Fic
2020-07-23 08:30:28 -07:00
parent ffedc41c26
commit 3eb2c0d787
5 changed files with 49 additions and 31 deletions

View File

@@ -27,24 +27,15 @@ firebase.initializeApp({
const messaging = firebase.messaging();
self.addEventListener("fetch", () => console.log("fetch"));
self.addEventListener("fetch", (fetch) => {
//required for installation as a PWA. Can ignore for now.
//console.log("fetch", fetch);
});
messaging.setBackgroundMessageHandler(function (payload) {
alert();
console.log(
"**********[firebase-messaging-sw.js] Received background message ",
payload
);
// Customize notification here
const notificationTitle = "Background Message Title";
const notificationOptions = {
body: payload.notification.body + "FROM SW",
icon: "logo240.png",
};
return self.registration.showNotification(
notificationTitle,
notificationOptions
"[SW]" + payload.notification.title,
payload.notification
);
});