Keep a live website when the application is in a state of completion (kill)

I am using websocket using Swift 2 to support some data between the application and the server. This websocket works fine at the front and background levels, but when I terminate (kill) the application, the websocket connection is disconnected. When you receive it again, the application will start working again.

Notes:

  • All background, VOIP and other permissions are provided.
  • As a rule, websocket does not work in the background, I figured out a solution to keep the work in the background and when the device is locked.
  • I also tried a quiet push notification, which calls a method for connecting to the web connector, a silent click notification occurs, but the method only works when the application returns.

So, any idea and suggestion appreciated how to keep a live website when the application is in a kill state?

Thanks in advance!

+5
source share
2 answers

It's impossible. When the user shuts down the application, everything goes with him, if this were not so, then users would not have a way to stop applications that perform strange things (except restarting the entire device).

In addition, you should not try to use exotic things to circumvent system restrictions, as this (in the end) will lead to rejection of the application for release to the store and / or to users who are dissatisfied with the battery life of your application.

+3
source

You can try to implement the behavior you are looking for using push notifications with available content, which gives you some time to download content in the background (more info here ), to do this, your payload should be structured as

{ "aps" : { "content-available" : 1 }, "data-id" : 1234 } 

Then do the following method to load the content or in your case do something with your web socket

 - (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 

This method should only be used to update any state of your application or to download some data, Apple does not recommend using it so that your socket is always alive, and I’m sure that it will ultimately reject your application if you use your the socket is always alive.

0
source

All Articles