Server Sent Events on iOS

José M. Pérez

José M. Pérez / August 08, 2011

2 min read0 views

You have probably heard about web sockets, which promise to be a better alternative to short and long polling to achieve real time updated websites. But maybe you didn't know about server sent events. They are nice to send information from server to client using the same server technology you probably have, using a lighter approach than polling.

Here you can find a nice explanation, and you can give it a try by visiting this Server-sent Event Demo from a capable browser.

How iOS devices react to Server Sent Events

Server Sent Event on iPhone

SSE will fire on iOS even if the page is not active

Having a look at how iPhone behaves when using Server Sent Events I realized that even if the tab showing a page using SSE is not the active one, Server Sent Events are processed. In short, events are processed as long as that page is loaded in any tab, no matter if it focused or not, and even after Safari is closed using Home button or the device is locked using the top button. The difference is that only when using Safari, a loading spinner is shown on top.

The behaviour of iPad is quite similar. It also processes SSE when it is locked or when a different tab is active, but it won't process them when closing Safari.

Is this how iPhone and iPad should behave? According to W3C, yes. They state:

The "push proxy" service uses a technology such as OMA push to convey the event to the mobile device, which wakes only enough to process the event and then returns to sleep.

But I can't find out how this can be useful at all. If only a notification system was available, a chat application could be implemented and notify the user whenever other person in the chat mentions him. But currently there's no way a non-active page can react to a server sent event, thus no useful event processing.