Search code examples
javascriptioswebsocketmobile-safari

Keep WebSocket alive in Mobile Safari


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.

Are there any other options?


Solution

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

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

    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.

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

    PS this also works on Android.