目前,我嘗試下載一些文件與AFNetworking,相對較小的文件,這似乎工作,但我想一個較輕較大的文件(17MB),它似乎只是崩潰,沒有任何錯誤。AFNetworking無法下載大文件
的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];
}
什麼樣的碰撞?是'EXC_BAD_ACCESS'?你嘗試了啓用殭屍對象。 – 2012-08-17 09:47:08
那麼它可能是內存的問題,您可以與outstream屬性設置的一個[文件流]試試[AFURLConnectionOperation(http://afnetworking.org/Documentation/Classes/AFURLConnectionOperation.html)(https://開頭開發商.apple.com /庫/的iOS /#文檔/可可/概念/流/用品/ WritingOutputStreams.html#// apple_ref/DOC/UID/20002274-BAJCABBC)。同樣創建一個'AFHTTPClient'實例,並且只使用它來爲你創建'NSURLRequest'就有點過分了。 'AFHTTPClient'意味着一個REST api客戶端,一個實例被所有的調用共享。 – rckoenes 2012-08-17 09:47:14
@ bitmapdata.com,它沒有給出太多的信息,只是線程1:信號SIGTRAP,我有殭屍對象啓用。 – 2012-08-17 09:49:25