Reputation: 898
I'm downloading files using NSOperation
(s) and adding them NSOperationQueue
. NSOperationQueue
is getting suspended when app goes in the background. Is there any work around if queue will not suspend in the background and start the next operation?
Upvotes: 5
Views: 2531
Reputation: 589
-(void)applicationDidEnterBackground:(UIApplication *)application {
__block UIBackgroundTaskIdentifier task = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask:task];
task = UIBackgroundTaskInvalid;
}];
}
Upvotes: 0
Reputation: 4296
While your queue is running use the UIApplication beginBackgroundTaskWithExpirationHandler
call to start a background task that will keep your downloads running.
I generally wrap up each operation with its own beginBackgroundTaskWithExpirationHandler
call, and queue the next one up before I call endBackgroundTask
that way the queue keeps running.
note an individual background task is limited to 10 minutes of operation, after that iOS will suspend the app.
Upvotes: 9