我正在將圖像下載到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