如何在 Angular Firebase 中将后台通知发送到前台以在 Angular 9 web 应用程序中显示通知?

use*_*473 6 javascript firebase firebase-cloud-messaging angular

我正在使用 Angular Firebase 来推送通知。前台消息一切正常,但是当我在 firebasw-messaging-sw.js 文件中添加“setBackgroundMessageHandler”调用来处理后台消息时,它会被触发,但我不确定如何从那里发送应用程序中的通知或将其转换前景。

messaging.setBackgroundMessageHandler(function (payload) {

    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    var data = payload.data;

});
Run Code Online (Sandbox Code Playgroud)

有人可以帮我弄这个吗?

我正在使用 Angular 9。

小智 4

setBackgroundMessageHandler 已弃用。尝试使用 onBackgroundMessage 和 ts 文件 _messaging.onBackgroundMessage = _messaging.onBackgroundMessage.bind(_messaging);

对我有用!