本文主要是介绍iOS ASIHttpRequest 和 AFNetWorking 实时监测下载进度,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
|
ASIHttpRequset 遵守< ASIProgressDelegate>协议 @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) { } | |
|
这篇关于iOS ASIHttpRequest 和 AFNetWorking 实时监测下载进度的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!