本文介绍了在Mobile Safari中保持WebSocket的活力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

屏幕锁定后,是否可以在Mobile-Safari中保持html 5网页WebSocket连接打开?

Is it possible to keep a html 5 web pages WebSocket connection open in Mobile-Safari once the screen is locked?

我想在整个过程中向用户发送持续更新这一天似乎很愚蠢,他们的屏幕应该总是被解锁以接收这些通知。

I want to send my users continuous updates throughout the day and it seems silly that their screens should always have to be unlocked to receive those notifications.

还有其他选择吗?

推荐答案

我发现了一种在移动Safari中保持WebSocket活跃的hacky方式。

I have found a hacky way to keep WebSocket alive in Mobile Safari.

基本上它是相同的解决方案至于。

Basically it's the same solution as for this question.

创建一个无限循环音频文件以保持Javascript运行:

Create an infinity looping audio file to keep Javascript running:

<audio loop src="http://www.sousound.com/music/healing/healing_01.mp3"></audio>

注意:启动音频文件需要一些用户交互。

Note: some user interaction is required to initiate the audio file.

如果WebSocket以与音频或视频文件相同的方式使浏览器保持活动状态,那将是很好的。

It would be nice if a WebSocket kept the browser alive in the same manner as an audio or video file.

PS这也适用于Android 。

PS this also works on Android.

这篇关于在Mobile Safari中保持WebSocket的活力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 18:27