I would like to leverage push notification for notification click and background message handling with Firebase Service Worker using Angular PWA's SwPush
in order to replace these following code in my firebase-messaging-sw.js
:
importScripts('https://www.gstatic.com/firebasejs/<firebase-version-here>/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/<firebase-version-here>/firebase-messaging.js');
firebase.initializeApp({
...
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
...
});
// Listener when click push notification
self.addEventListener('notificationclick', function (event) {
...
});
Here is my dependency version:
- Angular 8
- firebase v6.4.2
- @angular/fire v5.2.0
- @angular/service-worker v10.0.7
What I have done so far is following this guideline from @angular/fire. As far as I know, the Firebase Service Worker is supposed to register automatically. But when I subscribe to notificationClicks
, nothing happened.
this.swPush.notificationClicks.subscribe(...);
Could you please advise what I am missing? If you need more information, please let me know :)
ps. Everything looks good on foreground notification.
question from:
https://stackoverflow.com/questions/65841599/how-to-leverage-notificationclick-and-background-message-handling-using-angular 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…