iOS: Strategies for downloading very large data from web

ⅰ亾dé卋堺 提交于 2019-12-07 21:50:39

问题


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.

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~.

Initial Memory Usage

Memory Warning

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?


回答1:


It is better to use download task.

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

Then save the relative path to CoreData

If you use download task

  • You can resume if last download fail
  • Need less memory



回答2:


You can try AFNetworking to download large files.



来源:https://stackoverflow.com/questions/34089651/ios-strategies-for-downloading-very-large-data-from-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!