ASIHttpRequset遵守协议
@property (nonatomic, retain) ASIHTTPRequest *request;
// 下载路径
self.request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://dlsw.baidu.com/sw-search-sp/soft/2a/25677/QQ_V4.0.2.1427684136.dmg"]];
// 给下载任务设置路径和代理
[_request setDownloadDestinationPath:path];
[_request setDownloadProgressDelegate:self];
_begainDownloadTimer = [NSTimer scheduledTimerWithTimeInterval:3.f target:self selector:@selector(begainDownloadTimerAction) userInfo:nil repeats:NO];
// 开始下载
- (void)begainDownloadTimerAction
{
[_request startAsynchronous];
}
// 实时下载数据在这个代理方法里通知
- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
{
}
AFNetWorking
@property (nonatomic, retain) AFHTTPRequestOperation *operation;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://dlsw.baidu.com/sw-search-sp/soft/2a/25677/QQ_V4.0.2.1427684136.dmg"]];
//下载附件
self.operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
_operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[_operation start];
//下载进度控制
__block TestWifiSpeedVC *weakSelf = self;
[_operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
}
网友评论