【问题标题】:NSURLSession downloadTaskWithResumeData giving error after relaunch appNSURLSession downloadTaskWithResumeData 在重新启动应用程序后给出错误
【发布时间】:2015-05-19 14:51:52
【问题描述】:

我创建了一个下载任务。我已经使用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 目录包含下载数据,但无法访问。

【问题讨论】:

  • 听起来正是像这种情况:stackoverflow.com/questions/28360750/…
  • @Petesh 是的,我已经看到了,但这不是解决方案。
  • 我已经验证tmp包含重启后的数据。
  • 正是@Petesh,它会清除所有缓存的数据,但在执行任何操作之前,您可以检查数据是否存在recommended by Apple。详情请参考Stackoverflow Post
  • 但是每次重新启动时它都会损坏,我检查了路径不是我的应用程序临时目录。

标签: ios objective-c nsurlsession nsurlsessiondownloadtask


【解决方案1】:

重启应用后tmp上的链接文件中resumeData无效将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];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    相关资源
    最近更新 更多