TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jul 2016 |
Maintained by James Huynh, James Huynh.
Depends on: | |
FileMD5Hash | ~> 2.0.0 |
Reachability | ~> 3.1.1 |
ObjectiveCDM is a files download manager built on top of NSURLSession for iOS. It supports auto resume on internet connection recovery.
Choose ObjectiveCDM for your next project as your download manager!
platform :ios, '7.0'
pod "ObjectiveCDM", "~> 1.0.6"
ObjectiveCDM
can perform download on a batch of URL strings or NSURL
objects.
url
can be string or NSURL
objectfileSize
is not supplied, the download manager will trigger a HEAD
request to query for content length to fill in fileSize
.fileSize
. Default file hashing algorithm is SHA1. You can change by usingObjectiveCDM* objectiveCDM = [ObjectiveCDM sharedInstance];
objectiveCDM.fileHashAlgorithm = FileHashAlgorithmMD5;
#import "ObjectiveCDM.h"
[objectiveCDM downloadBatch:@[
@{
@"url": @"http://87.76.16.10/test10.zip",
@"destination": @"test/test10.zip",
@"fileSize": [NSNumber numberWithLongLong:11536384],
@"checksum": @"5e8bbbb38d137432ce0c8029da83e52e635c7a4f",
@"identifier": @"Content-1001"
},
@{
@"url": @"http://speedtest.dal01.softlayer.com/downloads/test100.zip",
@"destination": @"test/test100.zip",
@"fileSize": [NSNumber numberWithLongLong:104874307],
@"checksum": @"592b849861f8d5d9d75bda5d739421d88e264900",
@"identifier": @"Content-1002"
}
]];
objectiveCDM
instance first and then call startDownloadingCurrentBatch
later[objectiveCDM addBatch:@[
...
]];
...
[objectiveCDM startDownloadingCurrentBatch];
ObjectiveCDM* objectiveCDM = [ObjectiveCDM sharedInstance];
[objectiveCDM setInitialDownloadedBytes:1024];
ObjectiveCDM* objectiveCDM = [ObjectiveCDM sharedInstance];
[objectiveCDM setTotalBytes:1048576];
ObjectiveCDM* objectiveCDM = [ObjectiveCDM sharedInstance];
objectiveCDM.fileHashAlgorithm = FileHashAlgorithmMD5;
// objectiveCDM.fileHashAlgorithm = FileHashAlgorithmSHA512;
// objectiveCDM.fileHashAlgorithm = FileHashAlgorithmSHA1; // default
ObjectiveCDMUIDelegate
can be used to update progress of the batch download and update finish status of the whole batch
// ObjectiveCDM* objectiveCDM = [ObjectiveCDM sharedInstance];
// objectiveCDM.uiDelegate = self;
// ...
- (void) didReachProgress:(float)progress {
// this method is run on main thread
// ... update progress bar or progress text here
}
- (void) didFinishAll {
// this method is run on main thread
// ... update completed status of the whole batch
}
- (void) didFinishOnDownloadTaskUI:(ObjectiveCDMDownloadTask*) task {
// this method is run on main thread
// ... update completed status of a download task
}
- (void) didReachIndividualProgress:(float)progress onDownloadTask:(ObjectiveCDMDownloadTask*) task {
// this method is run on main thread
// ... update progress of a task
}
ObjectiveCDMDataDelegate
can be used to process file after finish downloading
// ObjectiveCDM* objectiveCDM = [ObjectiveCDM sharedInstance];
// objectiveCDM.dataDelegate = self;
// ...
- (void) didFinishDownloadObject:(ObjectiveCDMDownloadTask *)downloadTaskInfo {
// this method is run on background thread
// finish a task with ObjectiveCDMDownloadTask downloadInfo
}
- (void) didFinishAllForDataDelegate {
// this method is run on background thread
// do whatever needs to be done after a batch has been downloaded successfully
}
In didFinishDownloadObject
you will receive an ObjectiveCDMDownloadTask
instance. Inside this instance, you will be able to retrieve the following attributes
NSURL *url = downloadTaskInfo.url;
NSString *urlString = downloadTaskInfo.urlString;
NSString *destination = downloadTaskInfo.destination; // destination is the full path to the downloaded file
NSString *fileName = downloadTaskInfo.fileName;
NSString *checksum = downloadTaskInfo.checksum;
NSString *identifier = downloadTaskInfo.identifier;
[[ObjectiveCDM sharedInstance] addDownloadTask:@{@"url": @"http://download.thinkbroadband.com/5MB.zip", @"destination": @"test/5MB.zip"}];
NSArray *currentDownloadTask = [[ObjectiveCDM sharedInstance] downloadingTasks];
NSArray* downloadRateAndRemaining = [[ObjectiveCDM sharedInstance] downloadRateAndRemainingTime];
NSString *downloadRate = downloadRateAndRemaining[0];
NSString *remainingTime = downloadRateAndRemaining[1];
BOOL isDownloading = [[ObjectiveCDM sharedInstance] isDownloading];
git clone [email protected]:jameshuynh/ObjectiveCDM.git
ObjectiveCDM-Example/ObjectiveCDM-Example.xcworkspace
Cmd + R
to run the example project :-)Contribution, Suggestion and Issues are very much appreciated :). Please also fork and send your pull request!
ObjectiveCDM is available under the MIT license. See the LICENSE file for more info.