Code Monkey home page Code Monkey logo

lcdownloadmanager's Introduction

LCDownloadManager

一个简单易用的的下载助手。依赖于 AFN,实现断点续传,采取 Block 回调下载进度、文件大小、下载是否完成等。

心有猛虎,细嗅蔷薇。

致谢 AFNetworking

基于 AFNetworking 2.0

前言 Foreword

一个用来处理下载的库,基于AFN,实现了好几个东西,时间有限暂不一一说明,具体看代码。

代码 Code

    • 方法一:CocoaPods 导入:pod 'LCDownloadManager'
    • 方法二:把 LCDownloadManager 文件夹 (在 Demo 中) 拖到你的项目中。
  • 在相应位置导入头文件: #import "LCDownloadManager.h"

  • 调用下面的方法即可:

    // 当前下载任务
    AFHTTPRequestOperation *operation1 = nil;
    
    // 下载(提供了类方法和实例方法,根据使用习惯调用)
    operation1 = [LCDownloadManager downloadFileWithURLString:@"http://mw2.dwstatic.com/2/8/1528/133366-99-1436362095.mp4" cachePath:@"demo1.mp4" progress:^(CGFloat progress, CGFloat totalMBRead, CGFloat totalMBExpectedToRead) {
        
        // totalMBRead 和 totalMBExpectedToRead 单位是MB
        NSLog(@"Task1 -> progress: %.2f -> download: %fMB -> all: %fMB", progress, totalMBRead, totalMBExpectedToRead);
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"Task1 -> Download finish");
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        if (error.code == -999) NSLog(@"Task1 -> Maybe you pause download.");
        
        NSLog(@"Task1 -> %@", error);
    }];
    
    // 暂停(提供了类方法和实例方法,根据使用习惯调用)
    [LCDownloadManager pauseWithOperation:operation1];
  • iOS9 HTTP 不能正常使用的解决办法 (By isteven)

    1. Info.plist 中添加 NSAppTransportSecurity,类型 Dictionary
    2. NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads,类型 Boolean,值设为 YES

更新日志 2015.11.10 Update Logs (Tag: 1.0.1)

  • 添加对 CocoaPods 的支持:pod 'LCDownloadManager'
  • Demo 中添加演示如何防止用户重复点击下载,后续抽时间在库中实现。

更新日志 2015.07.10 Update Logs (Tag: 1.0.0)

  • 修复一个重要 BUG。这个 BUG 导致多任务下载时,不能正常暂停对应任务。
  • 提供类方法和实例方法,根据使用习惯调用。

联系 Support

授权 License

本项目采用 MIT license 开源,你可以利用采用该协议的代码做任何事情,只需要继续继承 MIT 协议即可。

lcdownloadmanager's People

Contributors

itofu avatar

Watchers

James Cloos avatar  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.