To allow your application to continue to safely run when it goes into the background, you must implement code in its AppDelegate class to ensure that the connection to the server shuts down gracefully when going into the background, and starts up when the application becomes active again.
This is important because in iOS, when an application goes into the background, it can have its network sockets invalidated, or the application may be shut down at any time. For correct behavior of the AppDelegate connection, the connection needs to be stopped when in background, and only started again when the application goes back to the foreground.
You must implement two appDelegate methods: applicationWillResignActive and applicationDidBecomeActive.
BOOL wasPreviouslyInBackground = NO; - (void)applicationWillResignActive:(UIApplication *)application { /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */ if([SUPMessageClient status] != STATUS_NOT_START) [SUPMessageClient stop]; wasPreviouslyInBackground = YES; } - (void)applicationDidBecomeActive:(UIApplication *)application { /* Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. */ if(wasPreviouslyInBackground) [SUPMessageClient start];