現在、AFNetworking を使用していくつかのファイルをダウンロードしようとしています。比較的小さなファイルの場合はこれでうまくいくようですが、少し大きなファイル (17MB) を試してみると、エラーなしでクラッシュするようです。
URL はローカル ファイルにリンクしています: http://test.local/wp-content/uploads/2012/07/test.pdf (シミュレーターで実行しているので、アクセス可能です)
私が得る唯一の出力は進捗ブロックにあります
進行状況: 0.009022
ファイルシステムを確認すると、ファイルはそこにあるように見えますが、数 kb しかありません。
これは AFNetworking の既知のエラーですか、それとも何か間違ったことをしているのかもしれません。
- (void)downloadIssue:(Issue *)issue
{
NSString *fileName = [issue.pdf lastPathComponent];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
NSURL *url = [NSURL URLWithString:issue.pdf];
AFHTTPClient *httpClient = [[[AFHTTPClient alloc] initWithBaseURL:url] autorelease];
NSURLRequest *request = [httpClient requestWithMethod:@"GET" path:issue.pdf parameters:nil];
AFURLConnectionOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"PDF DOWNLOAD COMPLETE");
issue.pdf_location = filePath;
// send out a notification with the issue
[[NSNotificationCenter defaultCenter] postNotificationName:@"PDF_DOWNLOAD_COMPLETE" object:nil userInfo:[NSDictionary dictionaryWithObject:issue forKey:@"issue"]];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"PDF DOWNLOAD FAILED");
// send out a notification with the issue
[[NSNotificationCenter defaultCenter] postNotificationName:@"PDF_DOWNLOAD_FAILED" object:nil userInfo:[NSDictionary dictionaryWithObject:issue forKey:@"issue"]];
}];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
float progress = (float)totalBytesRead / totalBytesExpectedToRead;
NSLog(@"progress: %f", progress);
[[NSNotificationCenter defaultCenter] postNotificationName:@"PDF_DOWNLOAD_PROGRESS" object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys: issue, @"issue", progress, @"progress", nil]];
}];
[_queue addOperation:operation];
}