Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep a live websocket when app is in terminated ( kill ) state

I am using websocket with Swift 2 to maintain some data between app and server. This websocket works fine in foreground and background state, but when I terminate ( kill ) app then websocket connection breaks. When coming again to the app it will start working again.

Notes:

  • All background, VOIP, and other permissions are given.
  • Generally, websocket don't work in the background, I have figured out a solution to keep working in background state and when the device is locked.
  • Tried silent push notification as well, which invokes method for websocket connection, silent push notification happens but the method works only when going back to the application.

So, any idea and suggestion appreciated about how to keep a live websocket when an app is in terminated ( kill ) state?

Thanks in advance!

like image 510
Hasya Avatar asked Apr 27 '16 09:04

Hasya


People also ask

How long can you keep a WebSocket open?

A WebSocket connection can in theory last forever. Assuming the endpoints remain up, one common reason why long-lived TCP connections eventually terminate is inactivity.

How do WebSockets stay open?

WebSocket uses HTTP as the initial transport mechanism, but keeps the TCP connection alive after the HTTP response is received so that it can be used for sending messages between client and server.

Does WebSockets work on mobile?

You can decide to use any WebSocket-based protocol that supports Android. Regardless of your choice, though, you need to consider the entire spectrum of challenges you'll face when it comes to WebSockets.


1 Answers

It is not possible. When the user terminates the app everything goes with it, if that wasn't the case then users would have no way to stop apps doing strange things (other than to restart the whole device).

Additionally you should not try exotic things to get around system restrictions as this will (eventually) lead to app rejection of you release to the store and / or users who are unhappy with battery life when your app is running.

like image 126
Wain Avatar answered Nov 15 '22 07:11

Wain