我的 firebase-messaging-sw.js 工作正常,可以正常显示后台通知,但在 notification.title 和 notification.click_action 正常工作时没有显示图标。
这是我的 Service Worker 的 messages.setBackgroundMessageHandler
messaging.setBackgroundMessageHandler(function (payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: '/image/logo.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
这就是结果
感谢您抽出时间提供帮助。
最佳答案
经过几天的尝试,我通过添加解决了问题
{"icon":"/image/logo.png"}
在 FCM 服务器发布请求正文中,而不是默认将其放在 firebase-messaging-sw.js 中。
IIS 服务器需要为托管 Web 项目提供静态内容,以便 logo.png 可以公开。
这是我更新的 JSON 格式的发布请求正文
{
"notification": {
"title": "New Appointment Requested",
"body": "5 to 1",
"icon": "/image/logo.png",
"click_action": "<host>/subpage"
},
"to": "token"
}
关于javascript - Firebase javascript后台服务 worker 通知图标不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43111026/