ADBDownloadManager 1.3.0

ADBDownloadManager 1.3.0

测试测试版
Lang语言 Obj-CObjective C
许可证 BSD 3.0
发布最新发布2015年3月

Alberto De Bortoli 维护。



  • Alberto De Bortoli

iOS 的下载管理器。实际上,需要下载文件而不需要任何外部库。

目标

  • 下载多个文件序列
  • 简化具有相同基本 URL 地址的文件序列的下载
  • 创建本地文件夹层次结构,映射远程路径(分割 URL)或将所有文件保存在同一目录中
  • 对于具有相同基本 URL 地址的文件,其组件不会用于创建文件夹
  • 下载在后台以序列方式发生
  • 取消尚未启动的下载

如果您想使用 CocoaPods 将此组件作为 pod 包含,只需在 Podfile 中添加以下行:pod "ADBDownloadManager"

尝试包含的示例项目或直接运行 pod try ADBDownloadManager 来测试。

简单用法

  • 将 ADBDownloadManager 类复制到您的项目中
  • 在您的类中导入 ADBDownloadManager.h
  • 创建 DownloadManager
NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
// without base URL
self.downloadManager = [[ADBDownloadManager alloc] initWithLocalPathFolder:documentsDirectory];
// or with base URL
self.downloadManager = [[ADBDownloadManager alloc] initWithBaseRemoteURL:@"http://www.myservice.com/"
                                                         localPathFolder:documentsDirectory];
  • 可选设置行为
self.downloadManager.forceDownoad = YES; // overwrites files, default is NO
self.downloadManager.createFoldersHierarchy = NO; // avoid the creation of the folders hierarchy, default is YES
  • 设置 delegatedataSource
self.downloadManager.delegate = self;
self.downloadManager.dataSource = self;

[self.downloadManager start];
  • 实现 ADBDownloadManagerDataSource 协议
#pragma mark - ADBDownloadManagerDataSource

- (NSUInteger)numberOfFilesToDownloadForDownloadManager:(ADBDownloadManager *)manager { ... }

- (NSString *)downloadManager:(ADBDownloadManager *)manager
 pathForFileToDownloadAtIndex:(NSUInteger)index { ... }
  • 实现 ADBDownloadManagerDelegate 协议
#pragma mark - ADBDownloadManagerDataSource

- (void)downloadManager:(ADBDownloadManager *)manager
 didDownloadFileAtIndex:(NSUInteger)index
          fromRemoteURL:(NSString *)remoteURL
            toLocalPath:(NSString *)localPath
                  bytes:(NSUInteger)bytes { ... }

- (void)downloadManager:(ADBDownloadManager *)manager
     didFailFileAtIndex:(NSUInteger)index
          fromRemoteURL:(NSString *)remoteURL
            toLocalPath:(NSString *)localPath
                  error:(NSError *)error { ... }

- (void)downloadManagerDidCompleteAllDownloads:(ADBDownloadManager *)manager
                                    failedURLs:(NSArray *)failedURLs
                                    totalBytes:(NSUInteger)totalBytes { ... }

- (void)downloadManagerWillStart:(ADBDownloadManager *)manager { ... }

- (void)downloadManagerDidStop:(ADBDownloadManager *)manager { ... }
  • 启动管理器
[self.downloadManager start];
  • 如果需要可以稍后停止它
[self.downloadManager stop];

就这么简单。

许可证

许可在新版 BSD 许可证下。

版权所有 © 2012, Alberto De Bortoli 保留所有权利。

在满足以下条件的情况下,允许重新分配和使用源代码和二进制形式,无论是否修改:* 源代码重新分配必须保留上述版权声明、本条件列表和以下免责声明。* 二进制形式的重新分配必须在文档中或随重新分配的提供其他材料中复制上述版权声明、本条件列表和以下免责声明。* 未经特定事先书面许可,不得使用 Alberto De Bortoli 或其贡献者的名称作为推广或支持从本软件派生的产品的标识。

本软件由版权所有者和贡献者按照“现状”提供,并且不提供任何明示或暗示的保证,包括但不限于对适销性和针对特定目的适用性的暗示保证。在任何情况下,Alberto De Bortoli均不对因使用本软件而产生的任何直接、间接、偶然、特殊、示范性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润的损失;或业务中断)承担任何责任,无论这种损害是由于何种原因引起的,无论基于何种责任理论,无论是在合同、严格责任还是侵权法上(包括疏忽或其它)。

资源

相关信息可在我的网站和Twitter上找到。