服务工作者可以停止由GCM API发送的推送通知吗? [英] Can service-worker stop push notification sent by GCM api?

查看:137
本文介绍了服务工作者可以停止由GCM API发送的推送通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前体系结构中,我使用GCM API提交推送通知. 这会触发服务工作者中的推送"事件.然后,服务人员将一些数据添加到通知中.

In my current architecture, I submit push notifications using the GCM API. This triggers a 'push' event in the service worker. The service worker then adds some data to the notification.

如果服务工作者由于某些错误而无法添加数据,我将收到空白通知.

If the service worker is unable to add the data, due to some error, I am getting a blank notification.

服务人员可以避免显示GCM发送的通知吗?

Can service workers avoid showing notifications sent by GCM?

推荐答案

来自推送通知指南,位于Google Developers:

From the Push Notifications guide at Google Developers:

您必须将{userVisibleOnly: true}参数传递给subscribe() 方法.这告诉浏览器通知将始终是 收到推送消息时显示.目前, 显示通知.

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.

结果是,如果您不显示任何响应推送的内容(在答应了浏览器之后),那么浏览器(无论如何是Chrome)都将为您显示内容.但是,这似乎可能会在某个时候改变.

The upshot is that if you don't show something in response to a push (after promising the browser that you will), the browser (Chrome, at any rate) will just show something for you. However, it seems likely that this will change at some point.

这篇关于服务工作者可以停止由GCM API发送的推送通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆