skandocious
skandocious

Reputation: 824

Socket.IO on iOS breaks when Safari is backgrounded

I've got a mobile web app that uses Socket.IO for WebSocket support and it works great except when I press the home button and then come back to Safari. If I background Safari by going to a different app and then come back to it the WebSocket connection doesn't work anymore.

Of note: going to a different tab in Safari and then coming back does not break the WebSocket -- I have to actually leave the Safari app.

Not get any errors on my web console when trying to send messages through the socket, it just doesn't work. Any ideas?

Upvotes: 2

Views: 4072

Answers (1)

moka
moka

Reputation: 23047

When application is "minimized" in iOS it is not just putting application on background, but more than that, it caches application, and actually stops it from processing, in order to save battery and prevent any background applications from working and doing "bad things".

That is why it brakes a connection, and this is normal behavior for iOS.

To restore session your server side application logic should implement sessions and ability to restore it on new connection if it was closed not a while ago.

For information, on Android stock browser will keep connection, but will freeze JS of processing, so if your application implements timeout it will drop Android client after your server will recognize it as not responding. As well going to another Tab will reduce performance of JS that way that internal stack of timed functions and callbacks will be slowed down and do not expect them to run on same frequency as when you are focused on the tab.

Upvotes: 7

Related Questions