仍支持适用于Android的Chrome上的前台FCM推送通知吗?

时间:2018-12-08 08:56:16

标签: javascript firebase firebase-cloud-messaging

Android上的Google chrome不会在前台触发FCM推送通知,但会在Service Worker上触发,并且可以在桌面上的google chrome上正常运行。

这是包含的内容,不会在chrome android上触发

const firebase = require("firebase/app");
const messaging = require("firebase/messaging");
messaging.onMessage((payload) => {
  // message received
})

github上获得以下文档

当应用程序具有浏览器焦点时,将通过index.html中的 onMessage 回调处理收到的消息。当应用程序不具有浏览器焦点时,将在firebase-messaging-sw.js中处理setBackgroundMessageHandler回调。

然后在docs之后生成通知(使用通知API W3C)。

function spawnNotification(theBody,theTitle) {
    var options = {
        body: theBody,
        // stack overflow icon
        icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
    }
    var n = new Notification(theTitle, options);
}

0 个答案:

没有答案
相关问题