iOS:从网络下载超大数据的策略 [英] iOS: Strategies for downloading very large data from web

查看:71
本文介绍了iOS:从网络下载超大数据的策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在从网络上下载较大文件(例如350MB大小的视频)时,我在iOS的内存管理方面苦苦挣扎. 这里的目标是下载这类文件,并将其存储在CoreData的Binary Data字段上.

I'm struggling with memory management in iOS while downloading relatively large files from the web (such as videos with 350MB size). The goal here is to download these kind of files and store it on CoreData on a Binary Data field.

此刻,我正在使用NSURLSession.dataTaskWithUrlNSURLSession.dataTaskWithRequest方法来检索这些文件,但是看起来这些方法并未处理诸如内存使用之类的问题,它们只是保持在将内存填满直到达到最大使用率时,当我达到380MB〜时向我发出内存警告.

At the moment I'm using NSURLSession.dataTaskWithUrl and NSURLSession.dataTaskWithRequest methods to retrieve these files, but it looks like these methods don't treat problems such as memory usage, they just keep on filling the memory until it reaches its maximum usage, leaving me with a memory warning when I reach 380MB~.

初始内存使用情况

内存警告

从网络上执行这种大数据检索而不会出现内存警告的最佳策略是什么? AlamoFire和其他库是否可以解决此问题?

What's the best strategy to perform this kind of large data retrieval from the web without reaching a memory warning? Does AlamoFire and other libs can deal with this problem?

推荐答案

最好使用下载任务.

并将视频另存为文件到文档目录.

And save the video as a file to Document or Library directory.

然后将相对路径保存到CoreData

Then save the relative path to CoreData

如果您使用下载任务

  • 如果上次下载失败,您可以继续
  • 需要更少的内存

这篇关于iOS:从网络下载超大数据的策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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