firebase云消息传递不';在我的javascript web应用程序中不显示
当我必须在web应用程序中显示firebase推送通知时,我遇到了问题。这很奇怪,因为如果我从邮递员那里取回,我可以看到通知出现在我的桌面上,但是如果我从我的web应用程序中取回,我看不到它 这是我的提取代码:firebase云消息传递不';在我的javascript web应用程序中不显示,javascript,firebase,push-notification,firebase-cloud-messaging,Javascript,Firebase,Push Notification,Firebase Cloud Messaging,当我必须在web应用程序中显示firebase推送通知时,我遇到了问题。这很奇怪,因为如果我从邮递员那里取回,我可以看到通知出现在我的桌面上,但是如果我从我的web应用程序中取回,我看不到它 这是我的提取代码: let obj = { to: deviceToken, data: { notification: { title: "Test Title", body: &quo
let obj = {
to: deviceToken,
data: {
notification: {
title: "Test Title",
body: "Test body",
icon: myIcon,
},
},
priority: "high"
};
fetch("https://fcm.googleapis.com/fcm/send", {
method: "POST",
body: JSON.stringify(obj),
cache: 'no-cache',
headers: {
"Content-Type": "application/json",
Authorization:
`key=${myApiKey}`,
},
})
.then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
});
和firebase-messaging-sw.js
messaging.setBackgroundMessageHandler(function(payload) {
console.log(
"[firebase-messaging-sw.js] Received background message ",
payload
);
var obj = JSON.parse(payload.data.notification);
// Customize notification here
var notificationTitle = obj.title;
var notificationOptions = {
body: obj.body,
icon: obj.icon,
};
return self.registration.showNotification(
notificationTitle,
notificationOptions
);
});
有人能帮我吗