angular / angular/angularfire

When pwa is in background, the serviceworker still uses onMessage not onBackgroundMessage!

未关闭
#3,469 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
7.8k
派生
2.2k
平均合并
22 小时 28 分钟
30 天内合并 PR
6

描述

Hello,

when I send a push notification to my app, the onMessage method is called even if it is in the background! Actually, the onBackgroundMessage should then be called, right? The problem now is that when I tap on the message box in Android, the Progressive Web Application is not brought to the foreground. Apparently Android thinks that the app is in the foreground? The message box disappears when I tap on it and the number of incoming messages also disappears from the app icon.

Is there any way to fix this?

The onMessage is defined in a service
`this.message$ = new Observable(sub => onMessage(this.messaging, it => sub.next(it))).pipe(
tap(payload => {this.print.info('MessagingService initFCMMessaging() FCM fmessage', { payload });})
);`

The onBackgroundMessage is defined in the firebase-messaging-sw.js with static text.

`messaging.onBackgroundMessage(function(payload) {
// Customize notification here
const notificationTitle = 'My title';
const notificationOptions = {
body: 'My Bodytext',
icon: '/firebase-logo.png' || '/assets/icons/icon-72x72.png'
};

self.registration.showNotification(notificationTitle, notificationOptions);
});`

I only noticed this because I defined a static text for the background message.

贡献指南

打开贡献指南

调研方向

首先比较 service 的 onMessage 设置与 firebase-messaging-sw.js 中的 onBackgroundMessage 注册,然后在 PWA 处于后台时重现该行为。当预期的 handler 已建立,并且通知点击行为已得到修正或限制已被明确记录时,即可视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, firebase, typescript
领域
frontend, web-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
28/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。