All Projects → onezens → Ycdownloadsession

onezens / Ycdownloadsession

Licence: mit
iOS background download video or file lib

Projects that are alternatives of or similar to Ycdownloadsession

Httptransfertasks
Cross Platform HTTP Transfers for downloading and uploading (supports background operations)
Stars: ✭ 87 (-78.78%)
Mutual labels:  background, download
Githubupdates
Cocoa framework to install application updates from GitHub releases.
Stars: ✭ 393 (-4.15%)
Mutual labels:  download
Negibox
All in one downloader 全能下载器
Stars: ✭ 335 (-18.29%)
Mutual labels:  download
Speedtest
Command line client for speedtest.net written in Go
Stars: ✭ 361 (-11.95%)
Mutual labels:  download
Maxurl
Finds larger/original versions of images and videos
Stars: ✭ 332 (-19.02%)
Mutual labels:  download
M3u8 Downloader
M3U8-Downloader 支持多线程、断点续传、加密视频下载缓存。
Stars: ✭ 369 (-10%)
Mutual labels:  download
Daisynet
1. - Alamofire与Cache封装 , 更容易存储请求数据. 2. - 封装Alamofire下载,使用更方便
Stars: ✭ 331 (-19.27%)
Mutual labels:  download
1click Webpage Screenshot
Entire page Screenshot extension for Google Chrome. I'm developing open source extension for Google Chrome. All extension are free for use. Let's make Chrome great again!
Stars: ✭ 406 (-0.98%)
Mutual labels:  download
Cprogressbutton
a circle progress button like iOS
Stars: ✭ 387 (-5.61%)
Mutual labels:  download
Net
Android上强大的网络请求
Stars: ✭ 344 (-16.1%)
Mutual labels:  download
Mjdownload
A delightful framework for multifile resumable broken downloads.
Stars: ✭ 345 (-15.85%)
Mutual labels:  download
Pyinstalive
Python script to download Instagram livestreams and replays.
Stars: ✭ 336 (-18.05%)
Mutual labels:  download
Bilili
🍻 bilibili video (including bangumi) and danmaku downloader | B站视频(含番剧)、弹幕下载器
Stars: ✭ 379 (-7.56%)
Mutual labels:  download
Vue Lazy Image Loading
Vue lazy image and background loading plugin.
Stars: ✭ 335 (-18.29%)
Mutual labels:  background
Ytmdl Web V2
Web version of ytmdl. Allows downloading songs with metadata embedded from various sources like itunes, gaana, LastFM etc.
Stars: ✭ 398 (-2.93%)
Mutual labels:  download
Dnslivery
Easy files and payloads delivery over DNS
Stars: ✭ 332 (-19.02%)
Mutual labels:  download
Rx Mvp
RxJava2+Retrofit2+RxLifecycle2+OkHttp3 封装RHttp 使用MVP模式构建项目
Stars: ✭ 343 (-16.34%)
Mutual labels:  download
Ahdownloadbutton
Customizable download button with progress and transition animations. It is based on Apple's App Store download button.
Stars: ✭ 370 (-9.76%)
Mutual labels:  download
Appupdater
🚀 AppUpdater一个专注于App更新,一键傻瓜式集成App版本升级的轻量开源库。(无需担心通知栏适配;无需担心重复点击下载;无需担心App安装等问题;这些AppUpdater都已帮您处理好。)
Stars: ✭ 406 (-0.98%)
Mutual labels:  download
Pluradl.py
Automated download of Pluralsight courses
Stars: ✭ 406 (-0.98%)
Mutual labels:  download

YCDownloadSession

Platform Support CocoaPods Carthage compatible Build Status

通过Cocoapods安装

安装Cocoapods

$ brew install ruby
$ sudo gem install cocoapods

Podfile

分成主要两个包:

  • Core : YCDownloader 只有下载器
  • Mgr : YCDownloader , YCDownloadManager 所有
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
    pod 'YCDownloadSession', '~> 2.0.2', :subspecs => ['Core', 'Mgr']
end

然后安装依赖库:

$ pod install

提示错误 [!] Unable to find a specification for YCDownloadSession 解决办法:

$ pod repo update master

通过Carthage安装

安装carthage:

brew install carthage

添加下面配置到Cartfile里:

github "onezens/YCDownloadSession"

安装, 然后添加Framework到项目:

carthage update --platform ios

用法

引用头文件

#import <YCDownloadSession.h>

AppDelegate设置后台下载成功回调方法

-(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler{
    [[YCDownloader downloader] addCompletionHandler:completionHandler identifier:identifier];
}

下载器 YCDownloader

创建下载任务

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

开始下载任务:

[[YCDownloader downloader] resumeTask:self.downloadTask];

暂停下载任务:

[[YCDownloader downloader] pauseTask:self.downloadTask];

删除下载任务:

[[YCDownloader downloader] cancelTask:self.downloadTask];

异常退出应用后,恢复之前正在进行的任务的回调

/**
 恢复下载任务,继续下载任务,主要用于app异常退出状态恢复,继续下载任务的回调设置

 @param tid 下载任务的taskId
 @param progress 下载进度回调
 @param completion 下载成功失败回调
 @return 下载任务task
 */
- (nullable YCDownloadTask *)resumeDownloadTaskWithTid:(NSString *)tid progress:(YCProgressHandler)progress completion:(YCCompletionHandler)completion;

下载任务管理器YCDownloadManager

设置任务管理器配置

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)resumeDownloadWithItem:(nonnull YCDownloadItem *)item;
    
/**
删除一个后台下载任务,同时会删除当前任务下载的缓存数据
     
@param item 创建的下载任务item
*/
+ (void)stopDownloadWithItem:(nonnull YCDownloadItem *)item;

蜂窝煤网络访问控制

/**
是否允许蜂窝煤网络下载,以及网络状态变为蜂窝煤是否允许下载,必须把所有的downloadTask全部暂停,然后重新创建。否则,原先创建的
下载task依旧在网络切换为蜂窝煤网络时会继续下载
     
@param isAllow 是否允许蜂窝煤网络下载
*/
+ (void)allowsCellularAccess:(BOOL)isAllow;
    
/**
获取是否允许蜂窝煤访问
*/
+ (BOOL)isAllowsCellularAccess;

使用效果图

单文件下载测试

单文件下载测试

多视频下载测试

多视频下载测试

下载通知

下载通知

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].