javascript - Firebase javascript后台服务 worker 通知图标不显示

标签 javascript firebase firebase-cloud-messaging iis-8 service-worker

我的 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);

});

这是我放置图标的位置 enter image description here

这就是结果

enter image description here

感谢您抽出时间提供帮助。

最佳答案

经过几天的尝试,我通过添加解决了问题 {"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/

相关文章:

javascript - 让 mathjax 在 rpc 之后重新加载页面

javascript - 在 cordova 移动应用程序上流式传输 Soundcloud

android - 如何 “append” Firebase查询快照到流

firebase - AuthenticationError 使用 Firebase Cloud Messaging 发送通知

Javascript 子类化。设置构造函数属性

javascript - PHP 或 JavaScript : Allow text to appear on specific page only

ios - 适用于 iOS 自定义键盘扩展的 Firebase Crashlytics

firebase - 在哪里可以查看和管理 FCM 中的主题

Android FCM 推送通知图标未显示在奥利奥设备中

firebase - FCM 通知单击始终在新选项卡中打开(网络应用程序 Polymer)