私は 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];
そして私の結果:
-1 バイトのうち 27129 を取得
-1 バイトのうち 127481 を取得
-1 バイトのうち 176699 を取得
では、AFNetworking は、zip ファイルや画像とは異なり、JSON データをダウンロードする場合、ダウンロードする実際のサイズを見積もることができないと思いますか?