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

Leave a Comment