在我当前的架构中,我使用 GCM API 提交推送通知。 这会触发 Service Worker 中的“推送”事件。然后,Service Worker 将一些数据添加到通知中。
如果服务工作人员由于某些错误而无法添加数据,我会收到空白通知。
Service Worker 能否避免显示 GCM 发送的通知?
最佳答案
来自Push Notifications guide在 Google 开发人员中:
You must pass a
{userVisibleOnly: true}
argument to the subscribe() method. This tells the browser that a notification will always be shown when a push message is received. Currently it’s mandatory to show a notification.
结果是,如果您没有显示某些内容来响应推送(在向浏览器 promise 您会显示内容之后),浏览器(至少是 Chrome)只会为您显示某些内容。然而,这种情况似乎可能会在某个时候发生改变。
关于push-notification - service-worker 可以停止 GCM api 发送的推送通知吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35202105/