Reputation: 67
I'm using the NSURLSession
background download service.
If my app is suspended and in background and a NSURLSessionDownloadTask
has finisehd the NSURLSessionDownloadDelegate
method
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
gets called as documented.
I observed that every time the delegate method is called the [UIApplication sharedApplication].backgroundTimeRemaining
) decreases from 30
seconds at the start to 0
after some downloads. If it reaches 0
the app crashes with "has active assertions beyond permitted time:".
This means the total time I have to handle completed background downloads (unzip, move) is 30
seconds in total. This may work for a couple of files but not if the download consists of a lot or big zip files.
This time interval is not mentioned in any Apple documentation. Is this a limitation of the NSURLSEssion
framework or did I implement it wrong?
thanks Christian
Upvotes: 1
Views: 684
Reputation: 36
You can use -[UIApplication beginBackgroundTaskWithExpirationHandler:] and -[UIApplication endBackgroundTask:] to let your app run long running background tasks. This will likely give your app much more time in the background before it is terminated.
Another possibility to consider is chaining your download requests so that when one completes and your URLSession delegate is called you process the file and issue the next download request. That way, you never have more than one file to process at a time (presuming it doesn't take too long to process a single file).
Upvotes: 2