我通过firebase通知管理器发送FCM通知。但通知图标没有选项。所以默认情况下它显示chrome。我的网络应用程序是使用reactjs制作的。如何更改该图标?
这是我的firebase serviceworker文件:
importScripts("https://www.gstatic.com/firebasejs/7.19.0/firebase-app.js");
importScripts(
"https://www.gstatic.com/firebasejs/7.19.0/firebase-messaging.js"
);
firebase.initializeApp({
messagingSenderId: "343676937800",
apiKey: "AIzaSyDCiXqVCawu6OPsvc87lPWqxoDIZ36RKmQ",
appId: "1:343676937800:web:ab233c9b1b935ed9439a7d",
projectId: "fcm-push-notify-bb24d",
});
const initMessaging = firebase.messaging();
App.js
import React, { useEffect } from "react";
import "./App.css";
import firebase from "./firebase";
function App() {
useEffect(() => {
const messaging = firebase.messaging();
messaging
.requestPermission()
.then(() => {
console.log("permission granted");
return messaging.getToken();
})
.then((token) => {
console.log(token);
})
.catch((error) => {
console.log(error);
});
}, []);
return <h2>Hello World</h2>;
}
export default App;
使用setBackgroundMessageHandler
处理自定义图标集。
https://github.com/firebase/quickstart-js/blob/b2f18e87b240868dd45ca141a328f8778b6de612/messaging/firebase-messaging-sw.js#L46-L57