2

我创建了一个下载任务。我已经取消了我的应用程序中的任务cancelByProducingResumeData并保存到磁盘。当用户重新启动应用程序并单击恢复按钮时,我再次启动了下载任务self.downloadTask = [session downloadTaskWithResumeData:resumableData];。但这会产生错误。

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

编辑:我已经验证了tmp模拟器上的目录包含 downloadData 但无法访问它。

4

1 回答 1

0

重新启动后,resuminData中的 tmp 文件上的应用程序链接无效。将resuminData中的“NSURLSessionResumeInfoLocalPath”字段更改为tmp文件的正确路径。

利用:

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];
于 2015-08-17T11:03:03.750 回答