Moved firebase messaging notification handling to messaging generation.
This commit is contained in:
@@ -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
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user