I am using background transfer service for downloading multiple videos using NSURLSession
. Downloading is working fine when the App is in background mode and I am satisfied with it. My problem is, I want callback for each video downloaded from a queue.
I was expecting the following method to be called for each video downloaded:
-(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier
completionHandler:(void (^)())completionHandler
and following method when system has no more messages to send to our App after a background transfer:
-(void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
But, both the methods are called when all downloads finish. I put 3 videos for downloading and then put App in background. Both methods called after all 3 videos were downloaded.
Here is what I am doing in those methods:
AppDelegate
-(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier
completionHandler:(void (^)())completionHandler
{
self.backgroundTransferCompletionHandler = completionHandler;
}
DownloadViewController
- (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.backgroundTransferCompletionHandler)
{
void (^completionHandler)() = appDelegate.backgroundTransferCompletionHandler;
appDelegate.backgroundTransferCompletionHandler = nil;
completionHandler();
}
NSLog(@"All tasks are finished");
}
Is it possible to show user a local notification on downloading of each video ? Or, I will have to wait til all videos complete downloading in the background ?
If the answer is NO, then my question is what is the purpose of these two different callbacks ? What separates them from each other ?