Iphone Can';t从ASIHTTPRequest中的下载目标路径访问图像
我正在将图像下载到Iphone HomeDirectory中的特定文件夹中,但无法访问它,因为它正在以随机生成的名称保存图像。因此,请帮助我如何在我的其他功能中正确访问它们Iphone Can';t从ASIHTTPRequest中的下载目标路径访问图像,iphone,objective-c,iphone-sdk-3.0,Iphone,Objective C,Iphone Sdk 3.0,我正在将图像下载到Iphone HomeDirectory中的特定文件夹中,但无法访问它,因为它正在以随机生成的名称保存图像。因此,请帮助我如何在我的其他功能中正确访问它们 - (void)fetchURL:(NSURL *)url { request1 = [ASIHTTPRequest requestWithURL:url]; NSString *str1 = [NSString stringWithFormat:@"savedImage%d",i1]; NSString *path
- (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);
看起来您有两个调用
setDownloadDestinationPath
。第一个设置到主目录子目录的路径,但第二个设置会更改它(如中的缓存部分所述)。您可以保存到任意一个位置,但不能同时保存到两个位置。看起来您有两个调用setDownloadDestinationPath
。第一个设置到主目录子目录的路径,但第二个设置会更改它(如中的缓存部分所述)。您可以保存到任意一个位置,但不能同时保存到两个位置。为什么要设置两次下载路径
[request1 setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
...
[request1 setDownloadDestinationPath:[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request1]];
为什么要将请求设置为下载到缓存?您应该只有一个下载路径。为什么要设置两次下载路径
[request1 setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
...
[request1 setDownloadDestinationPath:[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request1]];
为什么要将请求设置为下载到缓存?您应该只有一个downloadDestinationPath。我试图对一个请求进行注释,但仍然无法访问downloadDestinationPath中存储的图像,因为它们是用不同的名称保存的,并且还有一些HTML文件,不知道他们从何处提交。我试图对一个请求进行评论,但仍然无法访问downloadDestinationPath中存储的图像,因为他们正在使用不同的名称和一些HTML文件进行保存,不知道他们从何处提交。