男、これに困惑した。AFNetworkingでファイルをダウンロードしようとしていますが、私ができる最善の方法は、downloadProgressBlock で進行状況のバイトをキャプチャすることです。私は AFNetworking のさまざまなフォークを試しましたが、今は最新のビルドに戻っています。NSURLResponse も含めるように AFHTTPRequestOperation が変更されたように見えますが、最新のリリースでは削除されています。そして、以下のコードによると、「成功」ブロックは呼び出されません。ダウンロードされたバイトのログを取得し、^complete が呼び出されます。success と error は呼び出されません。
これに関するガイダンスは素晴らしいでしょう。データが返される場所と、それを取得して NSFileManager を使用する方法がわかりませんか? 画像などのストリームを書き込むのではなく、ファイルをダウンロードする必要があります。
編集:ドキュメントで提案されているように - (void)connection:didReceiveData をオーバーライドしてデータをキャプチャしようとしましたが、何もしていません。
// URL はhttp://mydomain.com/somezip.zipです
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", url]]];
AFHTTPRequestOperation *operation = [AFHTTPRequestOperation HTTPRequestOperationWithRequest:request success:^(id object) {
NSLog(@"hey, some success!");
} failure:^(NSHTTPURLResponse *response, NSError *error) {
NSLog(@"%@", error);
}];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {
// callback is sent in and works great. Just outputting to the console at the moment
SEL callme = NSSelectorFromString(callback);
[sender performSelectorOnMainThread:callme withObject:[NSNumber numberWithInt:bytesRead] waitUntilDone:NO];
}];
[operation setCompletionBlock:^{
NSLog(@"operation complete");
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];