Javascript 在Reactjs中使用Firebase集成时,未弹出Web前台推送通知
我在reactjs web应用程序中使用fcm进行推送通知。如果web应用程序在后台运行,我可以得到通知。但当我的应用程序在前台积极运行时,无法获取通知 Firebase初始化在我的项目中完成得非常完美,因为我在后台成功地获得了推送通知 firebase-messaging-sw.js 我是否需要对前台方法messaging.onMessage进行进一步修改,或者需要进行更多配置。请帮助我请尝试使用,而不是服务人员APIJavascript 在Reactjs中使用Firebase集成时,未弹出Web前台推送通知,javascript,reactjs,firebase,firebase-cloud-messaging,Javascript,Reactjs,Firebase,Firebase Cloud Messaging,我在reactjs web应用程序中使用fcm进行推送通知。如果web应用程序在后台运行,我可以得到通知。但当我的应用程序在前台积极运行时,无法获取通知 Firebase初始化在我的项目中完成得非常完美,因为我在后台成功地获得了推送通知 firebase-messaging-sw.js 我是否需要对前台方法messaging.onMessage进行进一步修改,或者需要进行更多配置。请帮助我请尝试使用,而不是服务人员API messaging.onMessage(function(payload)
messaging.onMessage(function(payload) {
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
icon: payload.notification.icon,
};
if (!("Notification" in window)) {
console.log("This browser does not support system notifications.");
} else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(notificationTitle,notificationOptions);
notification.onclick = function(event) {
event.preventDefault();
window.open(payload.notification.click_action , '_blank');
notification.close();
}
}
});
请尝试使用,而不是服务工作者API
messaging.onMessage(function(payload) {
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
icon: payload.notification.icon,
};
if (!("Notification" in window)) {
console.log("This browser does not support system notifications.");
} else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(notificationTitle,notificationOptions);
notification.onclick = function(event) {
event.preventDefault();
window.open(payload.notification.click_action , '_blank');
notification.close();
}
}
});
检查此答案的编辑检查此答案的编辑