NSURLSessionDownloadTask cancelByProducingResumeData返回null [英] NSURLSessionDownloadTask cancelByProducingResumeData return null

查看:285
本文介绍了NSURLSessionDownloadTask cancelByProducingResumeData返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NSURLSessionDownloadTask从服务器下载文件,该文件在后台会话中运行.我想保存恢复数据以在应用终止时恢复下载.但是,对cancelByProducingResumeData的调用始终返回null.我无法弄清楚这个问题,因为我以前曾经成功完成了一个可恢复下载任务的示例.有人遇到同样的问题吗?

I use NSURLSessionDownloadTask to download a file from server, it is run in a background session. I want to save resume data to resume the download when the app is terminated. However, the call of cancelByProducingResumeData always returns null. I cannot figure out the issue, cause I used to do a sample of resumable download task successful before. Does anybody get the same issue?

推荐答案

您知道请求是否满足cancelByProducingResumeData方法文档中概述的条件吗?

Do you know if the request satisfies the criteria outlined in the documentation for the cancelByProducingResumeData method?

只有满足以下条件,才能恢复下载:

A download can be resumed only if the following conditions are met:

  • 该资源自您首次提出请求以来就没有改变
  • 任务是HTTP或HTTPS GET请求
  • 服务器在其响应中提供ETag或Last-Modified标头(或两者)
  • 服务器支持字节范围请求
  • 系统尚未响应磁盘空间压力删除了临时文件
  • The resource has not changed since you first requested it
  • The task is an HTTP or HTTPS GET request
  • The server provides either the ETag or Last-Modified header (or both) in its response
  • The server supports byte-range requests
  • The temporary file hasn’t been deleted by the system in response to disk space pressure

这篇关于NSURLSessionDownloadTask cancelByProducingResumeData返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆