Can I http poll or use socket.io from a Service Worker on Safari iOS?

痴心易碎 提交于 2021-01-29 15:58:19

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/61550581/can-i-http-poll-or-use-socket-io-from-a-service-worker-on-safari-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!