AngularFire 捕获后台通知

标签 angular firebase push-notification angularfire2 angularfire

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

我有这个函数来捕获推送通知:

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

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

最佳答案

在 firebase-messaging-sw.js

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

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

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

对我有用!

关于AngularFire 捕获后台通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63264378/

相关文章:

IOS - 未从 firebase 控制台收到 FCM 推送通知

ios - 使用通知服务扩展振动 iphone 7,但它无法在后台运行 iOS 12.1

angular - Webpack 在输出时禁用图像名称的散列

javascript - typescript 代码 : How to calculate Totale=Sum(Subtotale) and price* quantita = subtotale Angular5

Angular 4 + PrimeNG 菜单 - 多个菜单项显示为事件状态

当应用程序从多任务托盘停止时,Android 应用程序未收到 Firebase 通知

firebase - Cloud Firestore 上每个集合的指标?

css - 在输入字段中嵌入图像

php - 字段 "to"必须是 JSON 字符串 [Firebase]

android - 如果 Android 应用程序不在中国 Android 手机的堆栈中,推送通知将不起作用