Created
May 15, 2011 11:18
-
-
Save Pablo-Merino/973060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *imageName =[NSString stringWithString:[(Tweet*)[tweets objectAtIndex:indexPath.row] author]]; | |
NSString *userImage =[NSString stringWithString:[(Tweet*)[tweets objectAtIndex:indexPath.row] profileImage]]; | |
NSArray *myArray = [userImage componentsSeparatedByString: @"/"]; | |
NSString *fileName = (NSString*)[myArray lastObject]; | |
NSString *picName =[NSString stringWithFormat:@"%@:%@", imageName, fileName]; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"]; | |
NSString* path = [dataPath stringByAppendingPathComponent:picName]; | |
UIImage* image = [UIImage imageWithContentsOfFile:path]; | |
if (!image) { | |
[activityIndicator startAnimating]; | |
UIImage *phoneImage=[UIImage imageWithData:[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:userImage]]]; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"]; | |
NSError *error; | |
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) | |
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; | |
NSString* path = [dataPath stringByAppendingPathComponent:picName]; | |
NSData* data = UIImagePNGRepresentation(phoneImage); | |
[data writeToFile:path atomically:YES]; | |
} | |
else{ | |
photo.image=image; | |
[activityIndicator stopAnimating]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment