From 209a0edbc8b219c125cf0ca79c10a71c0d8beefb Mon Sep 17 00:00:00 2001 From: wz Date: Fri, 2 Nov 2018 17:12:37 +0800 Subject: [PATCH] update some doc & 2.0.1 tag --- .github/{ISSUE_TEMPLATE => }/Bug_report.md | 0 README.md | 162 ++++++++++----------- YCDownloadSession.podspec | 4 +- YCDownloadSession/core/YCDownloadUtils.m | 2 + 4 files changed, 78 insertions(+), 90 deletions(-) rename .github/{ISSUE_TEMPLATE => }/Bug_report.md (100%) diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/Bug_report.md similarity index 100% rename from .github/ISSUE_TEMPLATE/Bug_report.md rename to .github/Bug_report.md diff --git a/README.md b/README.md index 6d22e2d..8d7f84d 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ [![Platform](https://img.shields.io/badge/platform-iOS-yellowgreen.svg)](https://github.com/onezens/YCDownloadSession) [![GitHub license](https://img.shields.io/github/license/onezens/YCDownloadSession.svg)](https://github.com/onezens/YCDownloadSession/blob/master/LICENSE) -[![Support](https://img.shields.io/badge/support-iOS%208%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)  +[![Support](https://img.shields.io/badge/support-iOS%208%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/) +[![CocoaPods](http://img.shields.io/cocoapods/v/YCDownloadSession.svg?style=flat)](https://cocoapods.org/pods/YCDownloadSession) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Build Status](https://travis-ci.com/onezens/YCDownloadSession.svg?branch=master)](https://travis-ci.com/onezens/YCDownloadSession) - ## 通过Cocoapods安装 安装Cocoapods @@ -28,7 +29,7 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' target 'TargetName' do - pod 'YCDownloadSession', '~> 2.0.0', :subspecs => ['Core', 'Mgr'] + pod 'YCDownloadSession', '~> 2.0.1', :subspecs => ['Core', 'Mgr'] end ``` @@ -85,7 +86,7 @@ carthage update --platform ios YCDownloadTask *task = [[YCDownloader downloader] downloadWithUrl:@"download_url" progress:^(NSProgress * _Nonnull progress, YCDownloadTask * _Nonnull task) { NSLog(@"progress: %f", progress.fractionCompleted); } completion:^(NSString * _Nullable localPath, NSError * _Nullable error) { - + // handler download task completed callback }]; ``` @@ -123,104 +124,89 @@ YCDownloadTask *task = [[YCDownloader downloader] downloadWithUrl:@"download_url ### 下载任务管理器`YCDownloadManager` -1. 设置任务管理器配置 - - ``` - NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject; - path = [path stringByAppendingPathComponent:@"download"]; - YCDConfig *config = [YCDConfig new]; - config.saveRootPath = path; - config.uid = @"100006"; - config.maxTaskCount = 3; - config.taskCachekMode = YCDownloadTaskCacheModeKeep; - config.launchAutoResumeDownload = true; - [YCDownloadManager mgrWithConfig:config]; - ``` - -2. 下载任务相关通知 - - ``` - //某一个YCDownloadItem下载成功通知 - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:kDownloadTaskFinishedNoti object:nil]; - //mgr 管理的所有任务完成通知 - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadAllTaskFinished) name:kDownloadTaskAllFinishedNoti object:nil]; - ``` - -3. 开始下载任务 - - ``` - YCDownloadItem *item = [YCDownloadItem itemWithUrl:model.mp4_url fileId:model.file_id]; - item.extraData = ...; - [YCDownloadManager startDownloadWithItem:item]; - ``` -4. 下载相关控制 - - ``` - /** - 暂停一个后台下载任务 +设置任务管理器配置 + +``` +NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject; +path = [path stringByAppendingPathComponent:@"download"]; +YCDConfig *config = [YCDConfig new]; +config.saveRootPath = path; +config.uid = @"100006"; +config.maxTaskCount = 3; +config.taskCachekMode = YCDownloadTaskCacheModeKeep; +config.launchAutoResumeDownload = true; +[YCDownloadManager mgrWithConfig:config]; +``` + +下载任务相关通知 + +``` +//某一个YCDownloadItem下载成功通知 +[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:kDownloadTaskFinishedNoti object:nil]; +//mgr 管理的所有任务完成通知 +[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadAllTaskFinished) name:kDownloadTaskAllFinishedNoti object:nil]; +``` + +开始下载任务 + +``` +YCDownloadItem *item = [YCDownloadItem itemWithUrl:model.mp4_url fileId:model.file_id]; +item.extraData = ...; +[YCDownloadManager startDownloadWithItem:item]; +``` +下载相关控制 + +``` +/** +暂停一个后台下载任务 - @param item 创建的下载任务item - */ - + (void)pauseDownloadWithItem:(nonnull YCDownloadItem *)item; +@param item 创建的下载任务item +*/ ++ (void)pauseDownloadWithItem:(nonnull YCDownloadItem *)item; - /** - 继续开始一个后台下载任务 +/** +继续开始一个后台下载任务 - @param item 创建的下载任务item - */ - + (void)resumeDownloadWithItem:(nonnull YCDownloadItem *)item; +@param item 创建的下载任务item +*/ ++ (void)resumeDownloadWithItem:(nonnull YCDownloadItem *)item; - /** - 删除一个后台下载任务,同时会删除当前任务下载的缓存数据 +/** +删除一个后台下载任务,同时会删除当前任务下载的缓存数据 - @param item 创建的下载任务item - */ - + (void)stopDownloadWithItem:(nonnull YCDownloadItem *)item; - ``` -5. 蜂窝煤网络访问控制 - - ``` - /** - 是否允许蜂窝煤网络下载,以及网络状态变为蜂窝煤是否允许下载,必须把所有的downloadTask全部暂停,然后重新创建。否则,原先创建的 - 下载task依旧在网络切换为蜂窝煤网络时会继续下载 +@param item 创建的下载任务item +*/ ++ (void)stopDownloadWithItem:(nonnull YCDownloadItem *)item; +``` +蜂窝煤网络访问控制 + +``` +/** +是否允许蜂窝煤网络下载,以及网络状态变为蜂窝煤是否允许下载,必须把所有的downloadTask全部暂停,然后重新创建。否则,原先创建的 +下载task依旧在网络切换为蜂窝煤网络时会继续下载 - @param isAllow 是否允许蜂窝煤网络下载 - */ - + (void)allowsCellularAccess:(BOOL)isAllow; +@param isAllow 是否允许蜂窝煤网络下载 +*/ ++ (void)allowsCellularAccess:(BOOL)isAllow; - /** - 获取是否允许蜂窝煤访问 - */ - + (BOOL)isAllowsCellularAccess; - ``` +/** +获取是否允许蜂窝煤访问 +*/ ++ (BOOL)isAllowsCellularAccess; +``` ## 使用效果图 -1. 单文件下载测试 +单文件下载测试 - ![单文件下载测试](http://src.onezen.cc/demo/download/1.gif) +![单文件下载测试](http://src.onezen.cc/demo/download/1.gif) -2. 多视频下载测试 +多视频下载测试 - ![多视频下载测试](http://src.onezen.cc/demo/download/2.gif) +![多视频下载测试](http://src.onezen.cc/demo/download/2.gif) -3. 下载通知 - - ![下载通知](http://src.onezen.cc/demo/download/4.png) - - -## TODO - -* [x] 4G/流量下载管理 -* [x] 对下载任务个数进一步优化和管理 -* [x] 下载完成后添加本地通知 -* [x] 301/302 视频模拟测试 -* [ ] Swift 版的下载 - 第一个稳定版发布后开始 (正在进行) - - -## 关于 - -* 如何反馈问题:[Bug_report.md](https://github.com/onezens/YCDownloadSession/blob/master/.github/ISSUE_TEMPLATE/Bug_report.md) +下载通知 +![下载通知](http://src.onezen.cc/demo/download/4.png) diff --git a/YCDownloadSession.podspec b/YCDownloadSession.podspec index 4b644dc..1e0d78a 100644 --- a/YCDownloadSession.podspec +++ b/YCDownloadSession.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "YCDownloadSession" - s.version = "2.0.0" + s.version = "2.0.1" s.summary = "iOS background download video or file" s.homepage = "https://github.com/onezens/YCDownloadSession" s.license = "MIT" @@ -27,6 +27,6 @@ Pod::Spec.new do |s| m.public_header_files = "YCDownloadSession/*.h" end - s.default_subspec = 'Core' + s.default_subspec = 'Core','Mgr' s.requires_arc = true end diff --git a/YCDownloadSession/core/YCDownloadUtils.m b/YCDownloadSession/core/YCDownloadUtils.m index 6b64963..a11bc91 100644 --- a/YCDownloadSession/core/YCDownloadUtils.m +++ b/YCDownloadSession/core/YCDownloadUtils.m @@ -83,6 +83,8 @@ + (NSUInteger)sec_timestamp { } @end + + #if YCDownload_Mgr_Item @interface YCDownloadItem(YCDownloadDB) @property (nonatomic, assign) NSInteger pid;