Save images from URL to iOS Directory
I want to save a lot (800-2000) images from server to iPhone app directory
(Documents directory).
First of all I have to check if those image are already on the iPhone
directory.
I use this code to download one image:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:@"http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg"]];
[NSURLConnection connectionWithRequest:request delegate:self];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory
stringByAppendingPathComponent:@"pkm.jpg"];
NSData *thedata = [NSData dataWithContentsOfURL:[NSURL
URLWithString:@"http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg"]];
[thedata writeToFile:localFilePath atomically:YES];
Please help me, any suggestions: 1. Save all images with the original name
on iPhone directory, NOT "pkm.jpg" 2. Save images with names: from
05052008321_bigger to 05052008350_bigger 3. Check if images are downloaded
already, DON'T Download again.
I know, maybe this is more than a question. But some suggestions,
directions will be really good.
Thanks in advance.
No comments:
Post a Comment