forked from renzifeng/ZFDownload
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: objective-c | ||
osx_image: xcode7.3 | ||
xcode_project: ZFDownload.xcodeproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,92 @@ | ||
# ZFDownload | ||
iOS download | ||
|
||
<p align="left"> | ||
<a href="https://travis-ci.org/renzifeng/ZFDownload"><img src="https://travis-ci.org/renzifeng/ZFDownload.svg?branch=master"></a> | ||
<a href="https://img.shields.io/cocoapods/v/ZFDownload.svg"><img src="https://img.shields.io/cocoapods/v/ZFDownload.svg"></a> | ||
<a href="https://img.shields.io/cocoapods/v/ZFDownload.svg"><img src="https://img.shields.io/github/license/renzifeng/ZFDownload.svg?style=flat"></a> | ||
<a href="http://cocoadocs.org/docsets/ZFDownload"><img src="https://img.shields.io/cocoapods/p/ZFDownload.svg?style=flat"></a> | ||
<a href="http://weibo.com/zifeng1300"><img src="https://img.shields.io/badge/weibo-@%E4%BB%BB%E5%AD%90%E4%B8%B0-yellow.svg?style=flat"></a> | ||
</p> | ||
|
||
## 特性 | ||
* 支持断点下载 | ||
* 异常退出,再次打开保留下载进度 | ||
* 实时下载进度 | ||
* 实时下载速度 | ||
|
||
## 要求 | ||
* iOS 7+ | ||
* Xcode 6+ | ||
|
||
## 效果图 | ||
|
||
 | ||
|
||
## 安装 | ||
### Cocoapods | ||
|
||
```ruby | ||
pod 'ZFDownload' | ||
``` | ||
|
||
## 使用 | ||
```objc | ||
[[ZFDownloadManager sharedInstance] download:urlString progress:^(CGFloat progress, NSString *speed, NSString *remainingTime, NSString *writtenSize, NSString *totalSize) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
// insert code here | ||
}); | ||
} state:^(DownloadState state) {}]; | ||
|
||
``` | ||
在cell上获取实时下载进度,遵守 ZFDownloadDelegate代理,然后实现 | ||
```objc | ||
#pragma mark - ZFDownloadDelegate | ||
- (void)downloadResponse:(ZFSessionModel *)sessionModel | ||
{ | ||
if (self.downloadObjectArr) { | ||
// 取到对应的cell上的model | ||
NSArray *downloadings = self.downloadObjectArr[1]; | ||
if ([downloadings containsObject:sessionModel]) { | ||
NSInteger index = [downloadings indexOfObject:sessionModel]; | ||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:1]; | ||
__block ZFDownloadingCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; | ||
__weak typeof(self) weakSelf = self; | ||
sessionModel.progressBlock = ^(CGFloat progress, NSString *speed, NSString *remainingTime, NSString *writtenSize, NSString *totalSize) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
cell.progressLabel.text = [NSString stringWithFormat:@"%@/%@ (%.2f%%)",writtenSize,totalSize,progress*100]; | ||
cell.speedLabel.text = speed; | ||
cell.progress.progress = progress; | ||
cell.downloadBtn.selected = YES; | ||
}); | ||
}; | ||
sessionModel.stateBlock = ^(DownloadState state){ | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
// 更新数据源 | ||
if (state == DownloadStateCompleted) { | ||
[weakSelf initData]; | ||
cell.downloadBtn.selected = NO; | ||
} | ||
// 暂停 | ||
if (state == DownloadStateSuspended) { | ||
cell.speedLabel.text = @"已暂停"; | ||
cell.downloadBtn.selected = NO; | ||
} | ||
}); | ||
}; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
# 联系我 | ||
- 微博: [@任子丰](https://weibo.com/zifeng1300) | ||
- 邮箱: [email protected] | ||
- QQ群:213376937 | ||
|
||
# License | ||
|
||
ZFDownload is available under the MIT license. See the LICENSE file for more info. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'ZFDownload' | ||
s.version = '0.0.1' | ||
s.summary = 'Download manager based on NSURLSession' | ||
s.homepage = 'https://github.com/renzifeng/ZFDownload' | ||
s.license = 'MIT' | ||
s.authors = { 'renzifeng' => '[email protected]' } | ||
s.platform = :ios, '8.0' | ||
s.source = { :git => 'https://github.com/renzifeng/ZFDownload.git', :tag => s.version.to_s } | ||
s.source_files = 'ZFDownload/**/*.{h,m}' | ||
s.framework = 'UIKit' | ||
s.requires_arc = true | ||
end |