特定のPDFを検索するメソッドがあります。ローカルで見つからない場合は、ASIHTTPRequest
非同期でダウンロードするために使用します。ただし、行:がコメント解除されると、要求は常に失敗し
[request setDownloadDestinationPath:currentDetailItem];
、要求が開始され、進行状況が100%まで増加してから、要求失敗ブロックが実行されます。
リクエストが失敗した場合の関連するNSLogは次のとおりです。
2012-08-16 12:08:34.398 XXXX[1675:707] Request started with url :http://XXXX.com/gwas/sites/default/files/Responding%20to%20Severe%20Weather%20Events.pdf
filePath :/var/mobile/Applications/322C24CF-9664-403D-9CC5-13C396F39F84/Documents/Responding%20to%20Severe%20Weather%20Events.pdf
2012-08-16 12:08:39.018 XXXX[1675:707] Request failed:HTTP/1.1 200 OK
メソッドのコードは次のとおりです。
- (void)setDetailItem:(NSString *)newDetailItem {
NSArray *downloadPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *components = [newDetailItem componentsSeparatedByString:@"/"];
NSString *filePath = [[downloadPaths objectAtIndex:0] stringByAppendingFormat:@"/%@", [components lastObject]];
currentDetailItem = filePath;
if (![self fileExistsLocally:[components lastObject]]) {
//Download the file
[self displayProgressView];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:newDetailItem]];
[request setDownloadDestinationPath:currentDetailItem];
[request setDownloadProgressDelegate:progressBar];
[request setCompletionBlock:^
{
[self showPdf:currentDetailItem];
[self hideProgressView];
NSLog(@"%f, Request finished :%@", progressBar.progress, request.responseStatusMessage);
}];
[request setFailedBlock:^
{
NSLog(@"Request failed:%@", request.responseStatusMessage);
[self hideProgressView];
[SVProgressHUD showErrorWithStatus:@"Request failed"];
}];
[request startAsynchronous];
NSLog(@"Request started with url :%@\nfilePath :%@", newDetailItem, currentDetailItem);
}
else {
[self showPdf:currentDetailItem];
}
}
行をコメントアウトする[request setDownloadDestinationPath:currentDetailItem];
と、リクエストは成功します。何か案は?ありがとう!