I am downloading images to a specfic folder in Iphone HomeDirectory but unable to access it as it is saving images in randomly generated names. So please help me how to access them properly in my other function.
- (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];
}
Accessing Image from other function
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 s开发者_如何学CtringByAppendingFormat:@"/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);
Why are you setting the download path twice?
[request1 setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
...
[request1 setDownloadDestinationPath:[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request1]];
And why are you setting the request to download to the cache? You should only have one downloadDestinationPath.
Looks like you have two calls to setDownloadDestinationPath
. The first one sets the path to a subdirectory of your home directory, but the second one then changes it (as described in the cache part of the documentation). You can save to either place, but not both.
精彩评论