Latest 0.0.1
Homepage https://github.com/Whiteands/HQDownLoadTool
License MIT
Platforms ios 9.0, requires ARC
Authors

基于NSURLSession的大文件下载器,支持断点下载,下载进度等

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, HQDownLoaderState) {
    /** 下载暂停 */
    HQDownLoaderStatePause,
    /** 正在下载 */
    HQDownLoaderStateDowning,
    /** 已经下载 */
    HQDownLoaderStateSuccess,
    /** 下载失败 */
    HQDownLoaderStateFailed
};

typedef void(^DownLoadStateChange)(HQDownLoaderState downLoaderState);
typedef void(^DownLoadMessage)(long long totalSize, NSString *downLoadedPath);
typedef void(^DownLoadPrograssChange)(float progress);
typedef void(^DownLoadSuccess)(NSString *downLoadedPath);
typedef void(^DownLoadFailed)(NSString *errorMsg);

@interface HQDownLoader : NSObject

@property (nonatomic, assign, readonly) HQDownLoaderState downLoaderState;

@property (nonatomic, copy) DownLoadStateChange stateChangeBlock;
@property (nonatomic, copy) DownLoadMessage messageBlock;
@property (nonatomic, copy) DownLoadPrograssChange progressBlock;
@property (nonatomic, copy) DownLoadSuccess sucessBlock;
@property (nonatomic, copy) DownLoadFailed failedBlock;

/**
 根据url地址下载

 @param url url地址
 */
- (void)downLoadWithURL:(NSURL *)url;
- (void)downLoadWithURL:(NSURL *)url messageBlock:(DownLoadMessage)messageBlock progress:(DownLoadPrograssChange)progressBlock success:(DownLoadSuccess)succcessBlock failed:(DownLoadFailed)failedBlock;

- (void)cancel;

- (void)pause;

- (void)resume;

- (void)cancelAndClean;

@end

用法

- (IBAction)downLoad:(id)sender {

    NSURL *url = [NSURL URLWithString:@"http://XXXXXXXXXXXXXXXX"];
    [self.downLoader downLoadWithURL:url messageBlock:^(long long totalSize, NSString *downLoadedPath) {

        NSLog(@"开始下载--%@--%lld",downLoadedPath,totalSize);

    } progress:^(float progress) {

        NSLog(@"下载中--%f",progress);

    } success:^(NSString *downLoadedPath) {

        NSLog(@"完成--%@",downLoadedPath);

    } failed:^(NSString *errorMsg) {

        NSLog(@"失败--%@",errorMsg);

    }];
}

支持CocoaPods

Podfile

platform :ios, '9.0'
pod 'HQDownLoadTool'

Latest podspec

{
    "name": "HQDownLoadTool",
    "version": "0.0.1",
    "summary": "HQDownLoadTool.",
    "description": "HQDownLoadTool.u4e0bu8f7du5668u652fu6301u65adu70b9u4e0bu8f7du7b49",
    "homepage": "https://github.com/Whiteands/HQDownLoadTool",
    "license": {
        "type": "MIT",
        "file": "FILE_LICENSE"
    },
    "authors": {
        "HQFlying": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/Whiteands/HQDownLoadTool.git",
        "tag": "0.0.1"
    },
    "source_files": [
        "Classes",
        "HQDownLoadTool/Classes/**/*.{h,m}"
    ],
    "exclude_files": "Classes/Exclude",
    "requires_arc": true
}

Pin It on Pinterest

Share This