Reputation: 175
I make a socket communication(iOS7).It works fine but it stop when my application goes at background.
Can anyone suggest , how to continue the socket communication? or suggest any other way to achieve it.
Thanks,
Upvotes: 0
Views: 735
Reputation: 364
When application enters into background iOS ensures that socket connection has to be disconnected .But you may be performing certain task in the background.Hence in the application delegate use beginbackgroundtaskexpirationhandler and create a instance of background task.For iOS 7 and above u will get a callback after 3 minutes and u have to end all the remaining task.Ensure that you call endbackgroundtask over UIApplication instance otherwise the app will be forcefully terminated.The socket connection gets disconnected after this duration.If you need to keep alive your socket connection you have to add the requirwement in plist file to support different backgroundmodes where apple supports seven different supports required
Upvotes: 1
Reputation: 15335
Did you check this :
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// put stuff(code) to make continue socket communication
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
For more Info: Check these LINK1 && LINK2 && LINK3 .
Upvotes: 0