Hey! I need to know how I can have my iOS Application start a download in the background of the application (like, have the download run in the AppDelegate file) so changing ViewControllers will not interrupt or cancel the download. I also need to be able to get the progress of the download (0.00000 - 1.00000), to set a UIProgressView object to, which also means I need a - (void)progressDidChangeTo:(int)progress function.
Hey! I need to know how I can have my iOS Application start a
Share
Just use ASIHTTPRequest it is way easier than NSURLRequest and does exactly what you need.
It examples that shows how to download in background and how to report progress.
I wouldn’t download anything in the AppDelegate directly. Instead I would create a separated class just for that purpose. Let’s call it
MyServiceI would then initialize that class in my app delegate.The class can work as a singleton or can be passed to each view controller that requires it.
In
MyServiceclass I would add the ASINetworkQueue and few methods to handle the requests when they are ready. Here is the code from ASI examples that you can use:If you need to set the progress bar. I would just expose the setDownloadProgressDelegate of ASINetworkQueue in my MyService class and set it in my ViewControllers like that:
BTW. If you need to continue downloading even when your app exits you can set
ShouldContinueWhenAppEntersBackgroundproperty of your request to YES.