-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDownloadTask.h
More file actions
executable file
·106 lines (90 loc) · 2.21 KB
/
DownloadTask.h
File metadata and controls
executable file
·106 lines (90 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// DownloadTask.h
// NetworkingCraft
//
// Created by YouXianMing on 15/6/11.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class DownloadTask;
@protocol DownloadTaskDelegate <NSObject>
@optional
/**
* 下载任务
*
* @param downloadTask 实例对象
* @param progress 进度显示
*/
- (void)downloadTask:(DownloadTask *)downloadTask withProgress:(CGFloat)progress;
/**
* 下载失败
*
* @param downloadTask 实例对象
* @param error 错误信息
*/
- (void)downloadTask:(DownloadTask *)downloadTask failedWithError:(NSError *)error;
/**
* 下载成功
*
* @param downloadTask 实例对象
*/
- (void)downloadTaskSucess:(DownloadTask *)downloadTask;
@end
@interface DownloadTask : NSObject
/**
* 代理
*/
@property (nonatomic, weak) id <DownloadTaskDelegate> delegate;
/**
* 标识符
*/
@property (nonatomic, strong) NSString *flag;
/**
* 下载地址
*/
@property (nonatomic, strong) NSString *urlString;
/**
* 存储的文件路径(不包括文件名字,如果不设置,则默认在/Library/Caches文件夹下)
*
* --------------------
* /Documents
* /Library/Caches
* /Library/Preferences
* /tmp
* --------------------
*
*/
@property (nonatomic, strong) NSString *filePath;
/**
* 文件名(如果不给文件名,则使用默认的文件名)
*/
@property (nonatomic, strong) NSString *fileName;
/**
* 绝对文件路径
*/
@property (nonatomic, strong, readonly) NSString *file;
/**
* 开始下载
*/
- (void)startDownload;
/**
* 停止下载
*/
- (void)stopDownload;
#pragma mark - 便利构造器
/**
* 便利构造器
*
* @param urlString 下载地址
* @param filePath 文件相对目录(可以不设置)
* @param fileName 文件名字(可以不设置)
* @param delegate 代理对象
*
* @return 实例对象
*/
+ (instancetype)downloadTaskWithUrlString:(NSString *)urlString
fileDirectory:(NSString *)filePath
fileName:(NSString *)fileName
delegate:(id)delegate;
@end