HMCDownloadManager 是一个支持在单个对象中下载多个文件的外套。
通过并发下载多个文件(相同或不同的 URL),我们可以为同时可以下载的最大项目数设置 maximumDownloadItem。我们可以选择背景下载(项目可以在应用程序处于后台时下载)或默认下载管理器。在不同的队列中对每个项目使用回调块。
要运行示例项目,克隆仓库,然后首先从 Example 目录运行 pod install
HMCDownloadManager 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'HMCDownloadManager'
HMCDownloadManager *defaultDownload = [HMCDownloadManager sharedDefaultManager];
HMCDownloadManager *backgroundDownload = [HMCDownloadManager sharedBackgroundManager];
defaultDownload.timeoutForRequest = 5.0;
defaultDownload.timeoutForResource = 3600;
backgroundDownload.timeoutForResource = 3600;
defaultDownload.maximumDownloadItems = 10;
dispatch_queue_t downloadQueue = dispatch_queue_create("Image Downloader", DISPATCH_QUEUE_SERIAL);
[defaultDownload startDownloadFromURL:url
progressBlock:^(NSURL *sourceUrl, NSString *identifier, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
// Update UI progress
} destination:^NSURL *(NSURL *sourceUrl, NSString *identifier) {
// return destination file
} finishBlock:^(NSURL *sourceUrl, NSString *identifier, NSURL *fileLocation, NSError *error) {
// Update when finished downloading
} queue:downloadQueue];
[downloadManager pauseDownload:url];
[downloadManager resumeDownload:url];
[downloadManager cancelDownload:url];
chuonghuynh, [email protected]
HMCDownloadManager 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。