QSessionDownloader 1.0.2

QSessionDownloader 1.0.2

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2016年9月

QianChia维护。



  • 作者
  • QianChia
  • 对 NSURLSession 文件下载的简单封装。

GitHub:QianChia | 博客:QianChia(Chinese)


安装

手动安装

  • QSessionDownloader 文件夹下的所有源文件拖到您的项目中。
  • 引入主头文件:#import "QSessionDownloader.h"

示例

  • 开始下载

        [[QSessionDownloader defaultDownloader] q_downloadWithURL:url progress:^(float progress) {
    
            dispatch_async(dispatch_get_main_queue(), ^{
                [button q_setButtonWithProgress:progress lineWidth:10 lineColor:nil backgroundColor:[UIColor yellowColor]];
            });
    
        } successed:^(NSString *targetPath) {
    
            NSLog(@"文件下载成功:%@", targetPath);
    
        } failed:^(NSError *error) {
    
            if ([error.userInfo[NSLocalizedDescriptionKey] isEqualToString:@"pauseDownload"]) {
    
                NSLog(@"暂停下载");
    
            } else if ([error.userInfo[NSLocalizedDescriptionKey] isEqualToString:@"cancelDownload"]) {
    
                NSLog(@"取消下载");
    
            } else {
    
                NSLog(@"文件下载失败:%@", error.userInfo[NSLocalizedDescriptionKey]);
            }
        }];
    
  • 暂停下载

        [[QSessionDownloader defaultDownloader] q_pauseWithURL:url];
    
  • 取消下载

        [[QSessionDownloader defaultDownloader] q_cancelWithURL:url];