2

I have created a download task. I have cancelled the task in my application with cancelByProducingResumeData and saved to disk. When user relaunch application and click on resume button I have again started the download task by self.downloadTask = [session downloadTaskWithResumeData:resumableData];. But this gives error.

Invalid resume data for background download. Background downloads must use http or https and must download to an accessible file

EDIT: I have verified the tmp directory on simulator contains the downloadData but not able to access that.

codester
  • 36,891
  • 10
  • 74
  • 72
  • Sounds *exactly* like this situation: http://stackoverflow.com/questions/28360750/nsurlsession-with-invalid-resume-data – Anya Shenanigans May 19 '15 at 15:03
  • @Petesh yes I have already seen that but that is not solution. – codester May 19 '15 at 15:09
  • I have verified `tmp` contains the data after relaunching. – codester May 19 '15 at 15:10
  • Exactly @Petesh, it clears all cached data, but before doing anything you can check for data existence `recommended by Apple`. Please refer [Stackoverflow Post](http://stackoverflow.com/questions/21895853/how-can-i-check-that-an-nsdata-blob-is-valid-as-resumedata-for-an-nsurlsessiondo) for more details. – Dipen Panchasara May 20 '15 at 12:58
  • But it's corrupting every time on relaunching and I have checked the path is not my application temp directory. – codester May 20 '15 at 14:11

1 Answers1

0

After restarting the application link on the tmp file in resuminData is not valid. Change the field-"NSURLSessionResumeInfoLocalPath" in resuminData, to the correct path of the tmp file.

use:

NSMutableDictionary* resumeDictionary = [NSPropertyListSerialization propertyListWithData:resumingData options:NSPropertyListMutableContainers format:NULL error:&error];
...
NSString* badFilePath = [resumeDictionary objectForKey:@"NSURLSessionResumeInfoLocalPath"];
...
[resumeDictionary setObject:trueTmpfile forKey:@"NSURLSessionResumeInfoLocalPath"];
...
NSData* newResumingData = [NSPropertyListSerialization dataFromPropertyList:resumeDictionary format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];