Workaround for iOS 8 WebApp Javascript/WS Bug

#1

Hello all,

I am using Autobahn Python as a home automation/integration server with HTML5/Javascript on the front end. All control data (commands and feedback) are sent through a websocket connection. The app is saved to the home screen on iOS/Android devices to act as a native app.

All has been working great (I have several servers running at multiple homes) until iOS 8 was release. There is a known bug in 8.0 - 8.1 that will kill all javascript timers in a WebApp when the device goes to sleep. There is no recovery and the app must be restarted. From what I’ve read, the bug was fixed in 8.1.1, but I’m still having issues with the websocket reconnecting. I thought I’d put it out there and see if any can think of a workaround.

sock.onclose = function(e) {

log("Connection closed (wasClean = " + e.wasClean + ", code = " + e.code + “, reason = '” + e.reason + “’)”);

$(’#fullOverlay’).css(‘display’, ‘block’);

$(’#overlayMsg’).css(‘display’, ‘block’);

setTimeout(function(){startSocket(wsuri)}, 1000);

}

``

Above is what I’ve been using to reconnect to the websocket when a user loses network connection. When the socket closes, it tries to reconnect every second until it successfully connects. The overlays prevent the user from performing any actions and notifies that the app is attempting to reconnect.

This all worked well until iOS 8 and even after 8.1.1 the websocket will not reconnect after sleep. Android and desktops all work perfectly.

Any ideas? Thanks!

0 Likes

#2

Hi Kevin,

could you try the demos here https://demo.crossbar.io/ with the iOS devices you have troubles with and check if the demo still works after coming back from sleep? These demos all use AutobahnJS, which does automatic WebSocket reconnection (with exponential, jittered backoff).

Apart from that, it’s my understanding that iOS devices automatically get updated to the “latest” version without user intervention, so “old devices” on the street is not a problem – or wrong?

Cheers,
/Tobias

···

Am Donnerstag, 4. Dezember 2014 20:30:39 UTC+1 schrieb Kevin Helton:

Hello all,

I am using Autobahn Python as a home automation/integration server with HTML5/Javascript on the front end. All control data (commands and feedback) are sent through a websocket connection. The app is saved to the home screen on iOS/Android devices to act as a native app.

All has been working great (I have several servers running at multiple homes) until iOS 8 was release. There is a known bug in 8.0 - 8.1 that will kill all javascript timers in a WebApp when the device goes to sleep. There is no recovery and the app must be restarted. From what I’ve read, the bug was fixed in 8.1.1, but I’m still having issues with the websocket reconnecting. I thought I’d put it out there and see if any can think of a workaround.

sock.onclose = function(e) {

log("Connection closed (wasClean = " + e.wasClean + ", code = " + e.code + “, reason = '” + e.reason + “’)”);

$(’#fullOverlay’).css(‘display’, ‘block’);

$(’#overlayMsg’).css(‘display’, ‘block’);

setTimeout(function(){startSocket(wsuri)}, 1000);

}

``

Above is what I’ve been using to reconnect to the websocket when a user loses network connection. When the socket closes, it tries to reconnect every second until it successfully connects. The overlays prevent the user from performing any actions and notifies that the app is attempting to reconnect.

This all worked well until iOS 8 and even after 8.1.1 the websocket will not reconnect after sleep. Android and desktops all work perfectly.

Any ideas? Thanks!

0 Likes