打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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) {



}




本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
MKN与AFN对比学习
网络(4.1)—AFNetworking多任务异步请求
一个异步网络请求的坑:关于NSURLConnection和NSRunLoopCommonModes
AFNetworking使用总结
[转]AFNetWorking使用笔记
ASIHTTPRequest详解
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服