angular - chrome (macOs) 不显示桌面推送通知

标签 angular macos google-chrome push-notification firebase-cloud-messaging

我已将基于 FCM 的推送通知集成到我的 Angular 应用程序中,推送通知会在 ubuntu 和 Windows 设备上触发,但无法在 macO 上运行。我附上了 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 上没有收到推送通知的任何人,请确保您已在“系统偏好设置”->“通知”->“Chrome”中为 Chrome 启用“通知”

即使我只是简单地从 Firebase 教程中复制和粘贴代码,我也在为这个问题而苦苦挣扎:)

关于angular - chrome (macOs) 不显示桌面推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55234458/

相关文章:

json - 如何将 JSON 响应映射到 Angular 4 中的模型

angular - 如何更新依赖注入(inject) token 值

javascript - 将数据从模型提取到变量

javascript - 由于超时而取消预渲染请求

html - Chrome 另存为 PDF 更改 CJK 字符

angularjs - Angular 1.x $q 到 Angular 2.0 beta

bash - 在 Mac 上设置 PATH 以使其在 session 之间持续存在

macos - 如何在 Azure Devops 中安装 Mac 预配配置文件?

php - Mac CLI PHP ini 文件位置

google-chrome - Selenium Chrome 抑制/取消客户端证书选择对话框