Marek Král
Marek Král

Reputation: 33

AngularFire catch background notifications

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

Answers (1)

Facundo Miño
Facundo Miño

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

Related Questions