iOS Background downloads when the app is not active
Add below in your - (void)applicationDidEnterBackground:(UIApplication *)application
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
and you are good to go... I have this in one of my published download manager app
This will work just fine. You can also check how much time you have, since apple only enable 10 minutes background tasks. Use:
NSTimeInterval ti = [[UIApplication sharedApplication]backgroundTimeRemaining];
NSLog(@"backgroundTimeRemaining: %f", ti); // just for debug
It is possible to start a background task when you begin the download:
Apps that are transitioning to the background can request an extra amount of time to finish any important last-minute tasks.
Executing a Finite-Length Task in the Background
However, such a task is limited to an undefined amount of execution time by the system. However, a 200Mb file download may be too large a task in this case.