使用 NSURLSession 清除网络故障后的临时下载文件 [英] Clearing temp download files after Network Failure using NSURLSession

查看:61
本文介绍了使用 NSURLSession 清除网络故障后的临时下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NSURLSession 来下载我的应用程序中的文件列表.我支持后台下载并且工作正常.但有时当应用程序运行时 WiFi 连接丢失背景,一些文件保留在临时目录中(com.apple.nsnetworkd)并且没有被删除.所以当我下载一组新文件时,这些文件仍然保留在目录中.这种情况会重复WiFi失败,文件集不断累积.有什么办法可以解决这个问题?如果我尝试手动删除这些文件会有什么问题吗?

I'm using NSURLSession to download a list of files in my app.I have support for background downloading and is working correctly.But some times when the WiFi connectivity is lost while the app is in background,some files remain in the temp directory(com.apple.nsnetworkd) and is not getting removed.So when i download a new set of files these files still remains in the directory.This situation repeats on WiFi failures and the set of files keeps accumulating.Any way to solve this issue? Will there be any problem if i try to remove these files manually?

如果 WiFi 连接处于活动状态,则一切正常,tmp 目录会自动清除.

If WiFi connection is active then everything works fine and tmp directory is cleared automatically.

推荐答案

尝试恢复任务,或者在需要释放空间时仍然发现 ios 来处理它,请不要担心

Trying resuming the task or don't worry if you still find it ios to handle it when required to free the space

来自文档可以在其中找到临时文件的文件 URL.由于文件是临时文件,因此您的委托方法必须在返回之前打开文件进行读取或将其移动到应用沙箱容器目录中的永久位置.

From Doc A file URL where the temporary file can be found. Because the file is temporary, your delegate method must either open the file for reading or move it to a permanent location in your app’s sandbox container directory before returning.

这篇关于使用 NSURLSession 清除网络故障后的临时下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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