Firebase javascript 后台服务工作者通知图标未显示

Firebase javascript background service worker notification icon not show

我的 firebase-messaging-sw.js 可以正常显示背景通知,但它没有显示图标,而 notification.title 和 notification.click_action 正常工作。

这是我服务人员的messaging.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);

});

这是我放置图标的地方

这是结果

感谢您花时间提供帮助。

把你的图片放在根目录下检查。

请参考这个URL-

https://github.com/firebase/quickstart-js

经过几天的尝试,我通过添加解决了这个问题 {"icon":"/image/logo.png"} 在 FCM 服务器 Post 请求正文中,而不是默认将其放在 firebase-messaging-sw.js 中。

并且 IIS 服务器需要为托管 Web 项目提供静态内容,以便 logo.png 可以作为 public。

这是我更新的 Post 请求正文 JSON 格式

{ 
"notification": {
    "title": "New Appointment Requested",
    "body": "5 to 1",
    "icon": "/image/logo.png",
    "click_action": "<host>/subpage"
},
 "to": "token"
}