【发布时间】:2016-02-19 04:19:15
【问题描述】:
当我使用 AFNetworking 2 时,我可以像这样使用 AFHTTPRequestOperation 取得进展:
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:aURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:_timeoutInterval];
AFHTTPRequestOperation *imageRequestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
imageRequestOperation.responseSerializer = [AFImageResponseSerializer serializer];
__weak AFHTTPRequestOperation *imageRequestOperationForBlock = imageRequestOperation;
[imageRequestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// ...
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// ...
}];
[imageRequestOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
if (progress) {
progress((float)totalBytesRead / totalBytesExpectedToRead);
}
}];
我使用AFHTTPSessionManager GET:parameters:success:failure:获取数据,但不知道如何在AFNetworking 3.0中获取下载进度。
【问题讨论】:
-
code.tutsplus.com/tutorials/… 的最后一段(锦上添花)应该对你有所帮助
-
@rokjarc 谢谢。想动态获取进度,教程没讲。
标签: ios objective-c afnetworking