美文网首页
iOS ASIHttpRequest 和 AFNetWorkin

iOS ASIHttpRequest 和 AFNetWorkin

作者: 雪中夜归人 | 来源:发表于2016-04-06 12:16 被阅读474次

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

    }

    相关文章

      网友评论

          本文标题:iOS ASIHttpRequest 和 AFNetWorkin

          本文链接:https://www.haomeiwen.com/subject/mkqmlttx.html