I checked a lot of documents, but could not find a solution for Resuming tasks using NSURLSession when the application is removed from the background or the device is rebooted.
I am dealing with amazon S3 to download some files. In this I can
- Upload a file to S3 using NSURLSessionUploadTask when the application is in the foreground and also in the background.
- Resume the task when the application crashed for some other reason at startup, and if the application is not removed from the background.
- Restart the task if I reboot the device during boot and if the application is not removed from the background.
Here is my code to get the fuctionality summary written in the applicationDidBecome Active appdelegate method.
// Initialize session config and the background session NSURLSession *l_taskSession = [self backgroundSession]; [l_taskSession getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) { if([uploadTasks count]) { for (int i=0; i<[uploadTasks count]; i++) { NSURLSessionUploadTask *uploadRequestTask = (NSURLSessionUploadTask*)[uploadTasks objectAtIndex:i]; [uploadRequestTask resume]; NSLog(@"-------- Upload Resumed ------- "); } } else if(![uploadTasks count]) { NSLog(@"------- There are no previous tasks -------"); } }];
Now the problem in both cases (2 and 3) mentioned above does not give a list of tasks to be performed, when I removed the application from the background and started it again, according to the code it falls into a different state if the condition and the logs
2015-06-12 17: 12: 32.902 AppName [162: 60b] ------- No previous tasks -------
So my question is allows you to resume tasks when you remove an application from the background? Or someone can just give me links links where I can find the answer for the same, any help is appreciated.
source share