【发布时间】:2019-03-19 05:53:43
【问题描述】:
我已将基于 FCM 的推送通知集成到我的 Angular 应用程序中,推送通知会在 ubuntu 和 Windows 设备上触发,但无法在 macOS 上运行。我附上了 firebase-messaging-sw.js 的代码:
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': SENDER_ID
});
self.addEventListener('fetch', event => {
event.waitUntil(async function() {
// Exit early if we don't have access to the client.
// Eg, if it's cross-origin.
if (!event.clientId) return;
// Get the client.
const client = await clients.get(event.clientId);
// Exit early if we don't get the client.
// Eg, if it closed.
if (!client) return;
// Send a message to the client.
self.clients.matchAll().then(function(clients) {
clients.forEach(function(client) {
client.postMessage({
msg: "Hey I just got a fetch from you!",
url: event.request.url
});
});
});
}());
})
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
// Customize notification here
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: '/firebase-logo.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
我们是否必须添加任何额外的配置来添加对 macOS Chrome 的支持?
【问题讨论】:
-
嘿。您是否找到任何适用于 mac OS 的解决方案?
标签: angular macos google-chrome push-notification firebase-cloud-messaging