我可以从 Safari iOS 上的 Service Worker 进行 http 轮询或使用 socket.io 吗? [英] Can I http poll or use socket.io from a Service Worker on Safari iOS?

查看:112
本文介绍了我可以从 Safari iOS 上的 Service Worker 进行 http 轮询或使用 socket.io 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个在 Android 上使用推送通知接收警报的 PWA.

当然,Safari/iOS 不支持推送通知,所以我需要实现一个等效的.我可以让我的 Service Worker 轮询数据,使用 http 长超时或 socket.io 吗? 收到警报后,软件将聚焦/创建一个应用程序窗口,然后处理用户体验.>

如果有罐头清单&对于服务工作者来说不能做或做 * 不做,那会很棒.

解决方案

不,这是不可能的.您根本无法在后台保持软件处于活动状态,也无法与您的服务器建立任何类型的开放连接.这是设计使然,因此某些软件代码不会一直运行、使用资源并可能以某种不明显的方式跟踪用户.

Android 方面也是如此:SW 不是一直在后台运行,而是休眠并被事件唤醒 - 例如接收新的推送消息 - 由操作系统/浏览器传递给它.然后在完成事件导致发生的任何工作后,软件再次进入睡眠"状态.

I'm building a PWA that on Android uses Push Notifications to receive alerts.

Of course, Safari/iOS doesn't support Push Notifications, so I need to implement an equivalent. Can I have my Service Worker poll for data, either using http long timeouts or socket.io? On receiving an alert, the SW will focus/create an app window to then deal with the UX.

If there is a list of cans & can'ts or dos * don'ts for service workers, that would be great.

解决方案

No, that is not possible. You cannot keep the SW alive in the background at all nor have an open connection of any sort to your server. This is by design so that some SW code is not constantly running, using resources, and potentially tracking the user in some non-obvious manner.

This is the same on Android side: the SW is not running in the background constantly but instead asleep and woken by events - such as receiving a new push msg - passed to it by the OS/browser. Then after doing whatever work the event causes to happen the SW goes to "sleep" again.

这篇关于我可以从 Safari iOS 上的 Service Worker 进行 http 轮询或使用 socket.io 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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