HMCDownloadManager 0.1.0

HMCDownloadManager 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2017

Maintained by Chuong Huynh.



  • By
  • Chuong M. Huynh



HMCDownloadManager is a wrapper supporting downloading multiple files within a singleton object.
By download multiple files concurrently (same or not same URL), we can set maximumDownloadItem for number of maximum items can be downloaded concurrently. We can choose between background (items can be downloaded when app is in background) or default download manager. Callback each block for each item in different queues.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0+
  • Xcode 8.3+

Features

  • Download multiple file within a singleton object
  • Support normal and background download
  • Copy to destination file when finish downloading
  • Support pause, resume, cancel downloading an item
  • Auto continue download file after interrupt without cancelling
  • Support multiple callback blocks for same url
  • Write/ read file only, don't use memory for store download item

Installation

HMCDownloadManager is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'HMCDownloadManager'

Usage

To get default download manager

HMCDownloadManager *defaultDownload = [HMCDownloadManager sharedDefaultManager];

To get background download manager

HMCDownloadManager *backgroundDownload = [HMCDownloadManager sharedBackgroundManager];

To edit maximum waiting time for the next data receiving for default manager

defaultDownload.timeoutForRequest = 5.0;

To edit maximum life time for downloading item

defaultDownload.timeoutForResource = 3600;
backgroundDownload.timeoutForResource = 3600;

To edit maximum downloading items concurrently

defaultDownload.maximumDownloadItems = 10;

To start download from URL

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];

To pause download from URL

[downloadManager pauseDownload:url];

To resume download from URL

[downloadManager resumeDownload:url];

To cancel download from URL

[downloadManager cancelDownload:url];

Author

chuonghuynh, [email protected]

License

HMCDownloadManager is available under the MIT license. See the LICENSE file for more info.