push-notification - service-worker 可以停止 GCM api 发送的推送通知吗?

标签 push-notification service-worker web-push push-api chrome-gcm

在我当前的架构中,我使用 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/

相关文章:

php - 如何向所选用户的浏览器发送通知

ios - iOS 中切换推送通知的 UX

javascript - 将图像添加到 Service Worker 中的缓存中

javascript - 为范围 ('https://.xxx.net/firebase-cloud-messaging-push-scope' 注册 ServiceWorker 失败)

Firefox 推送通知 - 通过curl 发送数据

javascript - 通过一次通话向所有订阅者发送网络推送通知

javascript - navigator.serviceWorker 用于开发环境

android - PendingIntent 并不总是在 android 中启动

android - 应用程序是否应该每 7 天调用一次 gcm.register() 以确保有效的注册 ID?

android - 如何在 Android 中添加自定义通知声音