当 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/