Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue download in background

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?

like image 819
Nitish Avatar asked Jun 19 '12 12:06

Nitish


People also ask

What is downloading in my background?

Use Task manager Right-click on the Taskbar and select Task Manager. In the Process tab, click on the Network column. This will show the process using the most bandwidth. Check the process that is using the most bandwidth currently. To stop the download, select the process and click on End Task.

Does Safari continue download in the background?

Anything can be downloaded and saved to the disk for later use, making your iOS device act more like a computer. On top of that, Safari supports background downloading so you can multitask like a boss while those files are being retrieved from the web.

How do I know if my Android is downloading in the background?

this is visible in the system settings -> data usage. you should then see a list of apps that are using data. it will also show the highest usage app.


1 Answers

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.

// Tell iOS this as a background task in case we get backgrounded
UIBackgroundTaskIdentifier taskId = [[UIApplication sharedApplication] 
          beginBackgroundTaskWithExpirationHandler:NULL];

//----------------------------------------------
// Perform your download operations here
//----------------------------------------------
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

// Tell iOS that we are done with stuff that needed to keep going even if backgrounded    
[[UIApplication sharedApplication] endBackgroundTask:taskId];
like image 139
progrmr Avatar answered Oct 25 '22 08:10

progrmr