【发布时间】:2017-02-21 18:38:43
【问题描述】:
我已多次尝试让桌面通知在 Chrome 中工作,但我没有找到一个文档来源,其中包含让桌面通知正常工作的分步过程。我遇到的每个资源要么已过时,要么与其他资源不一致。
我面临的问题是:一旦Service Worker收到push事件,
self.addEventListener('push', function (event) {
console.log(event);
event.waitUntil(
self.registration.showNotification(
event.data.title,
{
body: event.data.body,
icon: event.data.icon,
tag: event.data.tag
}));
});
event.data 为空。我希望它有我在这样的 POST 请求中作为 JSON 发送的数据:
POST https://fcm.googleapis.com/fcm/send HTTP/1.1
Content-Type: application/json
Authorization: key=<FCM Server Key here>
{
"data": {
"title": "Foo",
"body": "Bar"
},
"to": "<recipient ID here>"
}
奇怪的是注册脚本获得了一个看起来像https://android.googleapis.com/gcm/<recipient ID here> 的“订阅端点”,但我无法让 POST 通过,除非我按照网络上的其他示例将收件人 ID 设置为 @我发送的 JSON 中的 987654326@ 字段。
在我遇到的所有示例中,有多个 URL 被 POST 调用:
https://fcm.googleapis.com/fcm/send
https://android.googleapis.com/gcm/send
https://gcm-http.googleapis.com/gcm/send
我已经尝试了所有这三个,每次尝试都将收件人放在 API 地址的末尾(例如 https://fcm.googleapis.com/fcm/send/<recipient ID here> 或者在 JSON 正文中。我的目标是获得 Foo 和 从我发送到服务人员的self.registration.showNotification( 方法的数据中删除。
为什么event.data 为空?谁能指出我从头到尾的完整指南,它有利于 FCM 而不是 GCM?任何帮助将不胜感激。
【问题讨论】:
-
您好……找到答案了吗?
-
我遇到了同样的问题。你搞清楚了吗?
-
您好,找到答案了吗?
标签: javascript json google-cloud-messaging http-post firebase-cloud-messaging