我正在使用 AFNetworking 并且非常喜欢它。我需要从我的服务器获取 JSON 数据,这没关系,它运行良好。
我添加了 setDownloadProgressBlock 但我认为它不能与 JSON 下载一起使用:也许无法获得估计的要下载的字节数。
我的代码:
NSMutableURLRequest *request = [[VinocelaHTTPClient sharedClient] requestWithMethod:@"GET" path:@"ws/webapp/services/pull" parameters:nil];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
}];
[operation setDownloadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
NSLog(@"Get %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation start];
我的结果:
获取 27129 个 -1 个字节
获取 127481 个 -1 个字节
获取 176699 个 -1 个字节
所以,我认为 AFNetworking 在下载与 zip 文件或图像相反的 JSON 数据时无法估计要下载的实际大小?