Skip to content

Instantly share code, notes, and snippets.

@masbog
Created April 24, 2012 15:12
Show Gist options
  • Save masbog/2480460 to your computer and use it in GitHub Desktop.
Save masbog/2480460 to your computer and use it in GitHub Desktop.
Save image into temporary directory iOS
#define TMP NSTemporaryDirectory()
- (NSString*)setFileName:(NSString*)url
{
NSArray *tokenize = [url componentsSeparatedByString: @"/"];
NSString *imageFile = [tokenize objectAtIndex:([tokenize count]-1)];
//NSLog(@"%@",imageFile);
return imageFile;
}
//saving or get from temporary dir on some void
NSString *urlImage = "URL OF IMAGE";
NSString *filename = [self setFileName:urlImage];
NSString *uniquePath = [TMP stringByAppendingPathComponent:filename];
if(![[NSFileManager defaultManager] fileExistsAtPath:uniquePath])
{
ShowNetworkActivityIndicator();
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlImage]];
[request setTag:x];
[request setDelegate:self];
[request startAsynchronous];
}else
{
//do somethink if file exist
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment