我正在使用这个简单的 http 请求从 s3 服务器下载文件:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDidFinishSelector:@selector(done:)];
[request setDownloadDestinationPath:dest];
[request setDownloadProgressDelegate:pv];
[request setDelegate:self];
[request setShowAccurateProgress:YES];
[request setShouldContinueWhenAppEntersBackground:YES];
[request startAsynchronous];
pv.hidden = NO;
[request setFailedBlock:^(void) {
NSLog(@"Download failed: %@. reason:%@", url, [request.error localizedDescription]);
}];
[request setCompletionBlock:^(void){
NSString *zipFilePath = dest;
[SSZipArchive unzipFileAtPath:zipFilePath toDestination:desti];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:zipFilePath error:NULL];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ההורדה הסתיימה" message:@"מה ברצונך לעשות" delegate:self cancelButtonTitle:@"חזרה לתפריט" otherButtonTitles:@"נגן אפליקציה",nil];
[alert show];
}];
下载效果很好,但问题是请求总是成功,如果请求 url 中不存在文件,它也不会失败。