对于网站,如果同一应用在多个标签页中打开,则会收到多个 Firebase 通知



我正在使用 @angular/fire 作为角度 7 的 firebase 推送通知。当我的应用程序在多个选项卡中打开时,我收到相同的通知。

receiveMessage() {
this.angularFireMessaging.messages.subscribe(
(payload) => {
console.log("new message received. ", payload);
// this.currentMessage.next(payload);
console.log(thisref._router.url);
if(thisr[enter image description here][1]ef._router.url == '/playGame' && payload.data.gameId == window.localStorage.getItem(environment.gameId)) {
return
} else{
var notificationTitle = payload.notification.title;
var notificationOptions = {
body : payload.notification.body,
icon : payload.notification.icon,
// click_action : payload.notification.click_action
};
console.log(notificationOptions);
var notification = new Notification(notificationTitle,notificationOptions);
notification.onclick = function(event) {
// event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.open(payload.notification.click_action , '_self');
// notification.close();
}
}
})
}

我在前台浏览器中的每个选项卡都收到了一个通知。所以我设置了下面的代码,它对我有用。

if (!document.hidden) {
var notificationTitle = payload.notification.title;
var notificationOptions = {
body : payload.notification.body,
icon : payload.notification.icon,
// click_action : payload.notification.click_action
};
console.log(notificationOptions);
var notification = new Notification(notificationTitle,notificationOptions);
notification.onclick = function(event) {
// event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.open(payload.notification.click_action , '_self');
// notification.close();
}
}

相关内容

  • 没有找到相关文章

最新更新