ASIHttpRequset遵守協(xié)議
@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"]];
// 給下載任務(wù)設(shè)置路徑和代理
[_request setDownloadDestinationPath:path];
[_request setDownloadProgressDelegate:self];
_begainDownloadTimer = [NSTimer scheduledTimerWithTimeInterval:3.f target:self selector:@selector(begainDownloadTimerAction) userInfo:nil repeats:NO];
// 開(kāi)始下載
- (void)begainDownloadTimerAction
{
[_request startAsynchronous];
}
// 實(shí)時(shí)下載數(shù)據(jù)在這個(gè)代理方法里通知
- (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];
//下載進(jìn)度控制
__block TestWifiSpeedVC *weakSelf = self;
[_operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
}