I'm developing an in-house iOS app that requires an HTTP Server to be running all the time.
To do so, I use a background task to keep my application alive (playing audio in the background), and then I start the HTTP server. This is the code from my AppDelegate
.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
bgTask = [[MyBackgroundTask alloc] init];
[bgTask startBackgroundTaskWithTarget:self selector:@selector(backgroundCallback:)];
httpServer = [[HTTPServer alloc] init];
httpServer.interface = @"localhost";
[httpServer setType:@"_http._tcp."];
[httpServer setPort:8080];
[httpServer start];
}
And it works perfectly... almost!
Sometimes, the application, while running in the background, is being killed. For example:
Jun 24 11:27:24 My-iPhone SpringBoard[43] <Warning>: Application 'UIKitApplication:com.test.MyApp[0x668d]' was killed by jetsam.
And obviously the HTTP Server goes down. But when I relaunch the app after this termination, the HTTP Server won't start! (When I type localhost:8080
in Safari, I see an error message).
I don't have a problem with termination, that's completely okay. But I want my HTTP Server to be up and running when I reopen the app. But why that does not happen?
(Please note that if I close the app myself, everything works good).
Maybe :
or any other reasons from https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html