【问题标题】:When I set my downloadProgressBlock for AFNetworking, it is only ever called once at the very end当我为 AFNetworking 设置我的 downloadProgressBlock 时,它只会在最后被调用一次
【发布时间】:2013-12-19 20:20:38
【问题描述】:

我正在下载一张图片,并希望展示某种形式的下载进度:

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:post.url]];
    AFHTTPRequestOperation *imageOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    imageOperation.responseSerializer = [AFImageResponseSerializer serializer];

    [imageOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        NSLog(@"bytesRead: %d, totalBytesRead: %lld, totalBytesExpected: %lld", bytesRead, totalBytesRead, totalBytesExpectedToRead);
    }];

我还有一个完成块,然后是[imageOperation start];

但是,如果我选择要下载的图像,我所记录的只是:

bytesRead:72081,totalBytesRead:72081,totalBytesExpected:72081

为什么最后只给我信息?

【问题讨论】:

  • HTTP 服务器是否返回 Content-Length 标头?试试curl -I <URL>

标签: ios objective-c afnetworking nsurlrequest afhttprequestoperation


【解决方案1】:

它最终是由于我之前已经加载了该图像,所以我假设操作系统缓存了结果。所以它只返回了 100% 的进度,因为它已经下载了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2021-03-04
    相关资源
    最近更新 更多