【问题标题】:AngularFire catch background notificationsAngularFire 捕获后台通知
【发布时间】:2020-08-05 11:38:54
【问题描述】:

当 Angular 应用程序在后台(第二个选项卡)运行时,有什么方法可以捕获推送通知?

我有这个捕捉推送通知的功能:

  receiveMessage() {
    this.afMessaging.messages.subscribe((payload) => {
      console.log("new message received. ", payload);
      this.currentMessage.next(payload);
    });
  }

但当应用程序处于后台(第二个选项卡)时它不会触发。

【问题讨论】:

标签: angular firebase push-notification angularfire2 angularfire


【解决方案1】:

在 firebase-messaging-sw.js 中

messaging.onBackgroundMessage(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
});

并在ts文件中插入绑定函数

this.afMessaging.messaging.subscribe(
    (_messaging) => {
        _messaging.onBackgroundMessage = _messaging.onBackgroundMessage.bind(_messaging);        
    });

为我工作!

【讨论】:

  • this.afMessaging 是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-27
  • 2017-10-27
相关资源
最近更新 更多