Reputation: 33
Is there a any way to catch push notification while angular application is running in Background (second tab)?
I have this function for catch push notifications:
receiveMessage() {
this.afMessaging.messages.subscribe((payload) => {
console.log("new message received. ", payload);
this.currentMessage.next(payload);
});
}
But it don't fired when application is in background (second tab).
Upvotes: 2
Views: 1749
Reputation: 81
in firebase-messaging-sw.js
messaging.onBackgroundMessage(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
});
and in ts file insert bind function
this.afMessaging.messaging.subscribe(
(_messaging) => {
_messaging.onBackgroundMessage = _messaging.onBackgroundMessage.bind(_messaging);
});
works for me!
Upvotes: 4