使用FCM和ServiceWorker.js

时间:2019-01-17 06:47:11

标签: firebase firebase-cloud-messaging postman

我正在编写一个具有推送通知的网站。我正在使用邮递员以短信形式发送消息以进行推送通知。但是在我的服务人员那边,数据似乎总是空的。

这是我通过邮递员发送的邮件 enter image description here

我的服务人员代码

self.addEventListener('push', function (event) {
console.log(event);
var data = {};
if (event.data) {
    data = event.data.json();
    console.log(event.data.text);
} else {
    console.log(JSON.stringify(event));
    console.log('data is empty');
}
var title = data.title;
var message = data.body;
var icon = data.icon;
var click = data.click_action;

var notification = new self.Notification(title, {
    body: message,
    tag: 'simple-push-demo-notification',
    icon: icon
});

notification.addEventListener('click', function (click) {
    if (clients.openWindow) {
        clients.openWindow(click);
    }
});
});

在浏览器控制台窗口中,我不断看到文本:数据为空。

需要一些有关如何解决此问题的帮助吗?

0 个答案:

没有答案