1
我有一種方法尋找某個pdf,如果它沒有在本地找到它,它使用ASIHTTPRequest
異步下載它。但是,如果行 [request setDownloadDestinationPath:currentDetailItem];
未註釋,請求將始終失敗,請求開始並且進度增加,直到100%,然後執行請求失敗塊。ASIHTTPRequest set下載目標路徑失敗
這是相關NSLogs請求失敗時:
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];
出來,請求成功。有任何想法嗎?謝謝!
想必你可以單步,看看/爲什麼/ ASI被調用失敗的方法。 – JosephH 2012-08-16 11:35:58