iOS ASIHttpRequest 和 AFNetWorking 实时监测下载进度

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) {

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • AFNetwork是一个轻量级的网络请求api类库。是以NSURLConnection, NSOperation和...
    MissLu16阅读 935评论 0 3
  • 一、什么是YTKNetwork YTKNetwork是一个基于AFNetworking的网络层封装。 二、包括那几...
    Bo_cake阅读 2,464评论 0 1
  • 搞了两年多iOS开发了,网络请求这块儿,一直用的ASIHttpRequest,但是这个开源项目好长时间不维护。据说...
    oneDemo阅读 530评论 0 1
  • 这是一篇团队的成员之一斯科特·舍伍德所写的教程,它是专门从事混合定位解决方案的动态加载的定位软件公司。 网络——你...
    随风飘荡的小逗逼阅读 2,246评论 1 1
  • 访问网络的基本流程:5点 HTTP协议 2.通信过程 --------------请求的方法-----get 和 ...
    光明程辉阅读 1,103评论 0 2

友情链接更多精彩内容