IADownloadManager3 3.0.3

IADownloadManager3 3.0.3

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2017年6月

redbearder 维护。



 
依赖
EGOCache~> 2.0
AFNetworking~> 3.x
 


  • redbearder

##iOS下载管理器

###iOS的最简下载管理器

并行或顺序下载一组文件。

###它提供的内容

  • 易于集成和使用的iOS下载管理器。
  • 使用非常健壮的AFNetworking库轻松下载文件。
  • 只处理NSURL,永远不需要保留下载管理器的强或弱引用。
  • 按顺序和并行下载文件。
  • 确保每个文件(NSURL)只下载一次。
  • 在单个下载操作上支持多个监听器/委托。
  • 根据URL唯一地执行下载操作,永远不会重复下载一个URL。
  • 使用EGOCache在内存和磁盘上缓存已下载的文件。
  • 轻松添加和删除监听器以观察下载操作。
  • 单例类以实现快速访问和最小内存开销。
  • 确保UI线程永远不会被阻塞。
  • 委托或块事件回调。
  • 以上所有功能只需两行代码。

###动机

您是否想按并行或顺序下载一组图片,例如创建类似于Facebook时间轴单元格的单元格视图,该单元格包含多个图片。如果您尝试创建这样的东西,那么您就会意识到必须先下载一些图片,即时间轴单元格中的第一张图片必须在同一单元格的下一张图片之前被下载(记住我们在单元格中有多张图片)

IADownloadManager可以帮助您以并行顺序下载图片或任何其他文件。IASequentialDownloadManager可以帮助您按顺序下载一组URL。

###安装 ### 使用CocoaPods(推荐)

  1. 在您的机器上安装CocoaPods CocoaPods
  2. 创建Podfile
  3. pod 'IADownloadManager'添加到Podfile
  4. 在终端中运行'pod install'
  5. 打开App.xcworkspace

####手动安装

  1. 将IADownloadManager目录中的所有文件复制到您的项目中。
  2. 将ThirdParty目录中的文件复制到您的项目中
  3. CFNetwork.frameworkSecurity.framework添加到项目中,如果您不确定如何添加框架,请阅读以下SO 答复

###使用下载管理器,您应该具备以下先决条件

  • iOS 5
  • ARC

需要一个第三方(包含在项目的资源中)

###如何使用

每次下载操作都通过下载文件的NSURL进行标识,该NSURL是唯一的,并且会被缓存。

####使用代理回调按并行顺序下载文件。

开始下载操作

//Start the download operation, if the download operation is already started for this url,
//the urls will never be downloaded twice
[IADownloadManager downloadItemWithURL:url useCache:YES];

附加监听器

//Attach a listener to the url
[IADownloadManager attachListener:self toURL:url];

移除监听器

//Detach a listener to the url
[IADownloadManager detachListener:self];

代理方法

- (void)downloadManagerDidProgress:(float)progress;
- (void)downloadManagerDidFinish:(BOOL)success response:(id)response;

####使用代理回调按顺序下载文件。

开始下载操作

//Start the download operation, if the download operation is already started for these urls,
//the urls will never be downloaded twice
[IASequentialDownloadManager downloadItemWithURLs:urls useCache:YES];

附加监听器

//Attach a listener to the urls
[IASequentialDownloadManager attachListener:self toURLs:urls];

移除监听器

//Detach a listener to the url
[IASequentialDownloadManager detachListener:self];

代理方法

- (void)sequentialManagerProgress:(float)progress atIndex:(int)index;
- (void)sequentialManagerDidFinish:(BOOL)success response:(id)response atIndex:(int)index;

####基于块的回调。

还有一些用于通知下载事件的块,关于基于块的回调,请参考示例。