I am creating an application wherein I am downloading some data from server. While going in background I want that connection should continue running so that data can be downloaded. I know there is method in appDelegate
- (void)applicationDidEnterBackground:(UIApplication *)application
which is called when application enters background. But as the connection is created in viewController, how can it be managed in appDelegate?
Also is/are there other way(s) this can be done? I have gone through this link but is there a something simple to implement?
I don't know how you handle your data downloading exactly. But you can take a look at ASIHTTPRequest. It is very simple and straightforward, and works with ARC if you set the compiler flags to -fno-objc-arc. With this you only have to use
And that works.
Here you can see how ASIHTTPRequest works
Hope it helps!
[edit] Sorry I was incorrect, as was pointed out in the comments you can extend the time limit you have to perform operations once/before your app goes into the background. Here is Apple's Official Documentation
One way to do some operations that continue in the background is to create a separate thread to do the downloading. Inside the thread, bracket your download operations between calls to beginBackgroundTaskWithExpirationHandler: and endBackgroundTask. You don't need to check to see whether you are running in the background or not, you just always call these two methods.