测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可 | MIT |
Released上次发布 | 2016年7月 |
由 James Huynh,James Huynh 维护。
依赖 | |
FileMD5Hash | ~> 2.0.0 |
Reachability | ~> 3.1.1 |
ObjectiveCDM 是在 iOS 上基于 NSURLSession 构建的一个文件下载管理器。它支持网络连接恢复时的自动续传。
为您的下一个项目选择 ObjectiveCDM 作为您的下载管理器!
platform :ios, '7.0'
pod "ObjectiveCDM", "~> 1.0.6"
ObjectiveCDM
可以对一系列 URL 字符串或 NSURL
对象执行下载。
url
可以是字符串或 NSURL
对象fileSize
,下载管理器将触发一个 HEAD
请求以查询内容长度并填充 fileSize
。fileSize
。默认文件哈希算法是 SHA1。您可以使用以下方式更改它:ObjectiveCDM* 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
实例中,然后稍后调用 startDownloadingCurrentBatch
[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
可用于更新批量下载进度以及更新整个批次的完成状态。
// 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
可用于处理下载完成后文件的处理。
// 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
}
在 didFinishDownloadObject
方法中,您将接收到一个 ObjectiveCDMDownloadTask
实例。在这个实例中,您可以检索以下属性。
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
运行示例项目 :-)贡献、建议和问题都非常受欢迎 :). 请也进行分支并提交您的拉取请求!
ObjectiveCDM遵循MIT许可证。请参阅LICENSE文件以获取更多信息。