我正在将图像下载到Iphone HomeDirectory中的特定文件夹,但无法访问它,因为它将图像保存为随机生成的名称。所以请帮助我如何在我的其他功能中正确访问它们。其他功能无法从ASIHTTPRequest中的downloadDestination路径访问图像
- (void)fetchURL:(NSURL *)url
{
request1 = [ASIHTTPRequest requestWithURL:url];
NSString *str1 = [NSString stringWithFormat:@"savedImage%d",i1];
NSString *path = [self.documentsDirectoryPath stringByAppendingPathComponent:str1];
NSLog(@"saved image path %@",path);
[request1 setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
//path];
//[request1 setTemporaryFileDownloadPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"1"]];
[request1 setAllowResumeForFileDownloads:YES];
[request1 setDelegate:self];
[request1 setDidFinishSelector:@selector(URLFetchWithProgressComplete:)];
[request1 setDidFailSelector:@selector(URLFetchWithProgressFailed:)];
[request1 setDownloadDestinationPath:[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request1]];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[request1 startAsynchronous];
i1++;
//[request1 setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
//[request setDownloadProgressDelegate:imageProgressIndicator1];
//[self.networkQueue addOperation:request1];
}
访问映像
ASIDownloadCache *cache = [[[ASIDownloadCache alloc] init] autorelease];
//NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
self.documentsDirectoryPath = NSHomeDirectory();
//[paths objectAtIndex:0];
[cache setStoragePath:self.documentsDirectoryPath];
NSLog(@"path %@",self.documentsDirectoryPath);
self.destinationPath = [documentsDirectoryPath stringByAppendingFormat:@"/Library/Caches/ASIHTTPRequestCache/SessionStore"];
//NSString *PathStr = [NSString stringWithFormat:@"savedImage%d",i];
//NSString *appFile = [self.destinationPath stringByAppendingPathComponent:PathStr];
//NSString *path = [self.documentsDirectoryPath stringByAppendingPathComponent:PathStr];
//NSLog(@"images path %@",path);
NSLog(@"Download Destination Path %@",[request1 downloadDestinationPath]);
imageView.image = [UIImage imageWithContentsOfFile:[request1 downloadDestinationPath]];
//self.destinationPath];
//[request1 downloadDestinationPath]];
NSLog(@"Image %@ and %d",imageView.image,i);
我试图评论一个请求,但仍然无法访问存储在downloadDestinationPath中的图像,因为它们使用不同的名称和一些HTML文件保存,不知道它们来自哪里。 – user366584 2011-01-11 10:38:02