Giter Site home page Giter Site logo

whc_filedownloaddemo's Introduction

WHC_FileDownloadDemo

/*

  • qq:712641411
  • iOS大神qq群:460122071 */

目前封装最好使用最简单的文件下载第三方iOS网络下载库 #具体使用方式请下载demo阅读里面很详细

##运行效果 image

####Use Example

//开始下载文件代码片段
BOOL            _isDownload;
//保存下载文件路径
NSString      * _filePath = [NSString stringWithFormat:@"%@/Library/Caches/WHCFiles/",NSHomeDirectory()]; 
//自定义存储下载文件名
NSString      * _fileName = @"吴海超下载测试文件.mp4";
//当前下载对象
WHC_Download  * _download = [WHCDownloadCenter startDownloadWithURL:url 
                                                           savePath:_filePath  
                                                       savefileName:_fileName 
                                                           delegate:self];

//下载代理实现
#pragma mark - WHCDownloadDelegate
//得到第一响应
- (void)WHCDownload:(WHC_Download *)download didReceiveResponse:(NSURLResponse *)response{
    NSLog(@"下载开始");
}

//接受下载数据处理下载显示进度以及下载速度
- (void)WHCDownload:(WHC_Download *)download didReceivedLen:(uint64_t)receivedLen totalLen:(uint64_t)totalLen networkSpeed:(NSString *)networkSpeed{
    CGFloat  percent = (CGFloat)receivedLen / totalLen * 100.0;
    _percentLab.text = [NSString stringWithFormat:@"%.1f%%",percent];  //显示下载百分比
    _downProgressV.progress = percent / 100.0;                         //显示下载进度
    //显示下载文件大小
    _curDownloadSizeLab.text = [NSString stringWithFormat:@"%.1fMB/%.1fMB",((CGFloat)receivedLen / 1024.0) / 1024.0 ,((CGFloat)totalLen / 1024.0) / 1024.0];
    _downloadSpeedLab.text = networkSpeed; //显示当前下载速度
}

//下载出错处理
- (void)WHCDownload:(WHC_Download *)download error:(NSError *)error{
    if(error){
        NSString  * strError = error.description;
        switch (error.code) {
            case GeneralErrorInfo:
                NSLog(@"一般出错");
            break;
            case NetWorkErrorInfo:
                NSLog(@"网络错误");
            break;
            case FreeDiskSpaceLack:
                NSLog(@"磁盘剩余空间不足");
            break;
            default:
            break;
        }
        UIAlertView  * alert = [[UIAlertView alloc]initWithTitle:@"下载出错误" message:strError delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
    _isDownload = NO;
}

//下载结束处理
- (void)WHCDownload:(WHC_Download *)download filePath:(NSString *)filePath isSuccess:(BOOL)success{
    NSLog(@"filePath = %@",filePath);
    if(success){
        UIAlertView  * alert = [[UIAlertView alloc]initWithTitle:@"阿超已经帮你下载完成" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
    _isDownload = NO;
}

whc_filedownloaddemo's People

Contributors

netyouli avatar

Watchers

James Cloos avatar liuliudong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.