【发布时间】:2020-01-29 15:12:42
【问题描述】:
我这样调用pushManager.subscribe 函数:
return navigator.serviceWorker.register(process.env.PUBLIC_URL + '/sw-notifications.js').then(function(registration) {
let subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: urlBase64ToUint8Array(publicKey)
};
return registration.pushManager.subscribe(subscribeOptions);
})
.then(function(pushSubscription) {
return pushSubscription;
});
这很好用,它返回一个看起来像这样的对象:
{"endpoint":"https://fcm.googleapis.com/fcm/send/foo:bar","expirationTime":null,"keys":{"p256dh":"key","auth":"key"}}
文档说要向endpoint URL 发送一个 POST 请求以向用户发送推送通知。
很遗憾,it doesn't seem to specify 该请求使用什么样的正文。
我尝试用谷歌搜索,发现 this page 说这是旧版 API。
现在我很困惑。为什么最新 Chrome 上的 PushManager 会返回旧版 API?我应该使用其他东西吗?或者这仍然可以使用?
我正在尝试为我的网站启用推送通知,但无法弄清楚所有这些拼图是如何对齐的。
【问题讨论】:
标签: javascript google-chrome push-notification firebase-cloud-messaging