I have checked many docs but could not found solution for Resuming tasks using NSURLSession when app removed from background or on device reboot.
I am dealing with amazon S3 to upload some files, In that I am able to
- Upload file to S3 using NSURLSessionUploadTask, when app is in foreground as well as in background.
- Resume task when app crashed due to any other reason while uploading and if app is not removed from background.
- Restart task if I reboot device while uploading and if app is not removed from background.
Here is my code to achive resume fuctionality written in applicationDidBecomeActive method of appdelegate.
// 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 is in both the case (2 & 3) mentioned above it doesn't give list of tasks that were in progress, when I removed app from background and launched again, as per code it falls in else if condition and logs
2015-06-12 17:12:32.902 AppName[162:60b] ------- There are no previous tasks -------
So my question is this possible to resume tasks when app removed from background ? Or can anybody just give me reference links where I can find answer for the same, any help is appreciated.