I am new in iPhone Please tell me anyone if i want to download 100 images at 1st time,then for 2 nd time in all 100 images only the 10 images will modified,i want to overwrite that 10 images how to do this??
-
1From where the Image Download informations (i.e name of image and link to download) comes ? Is it from webservice? – Rohan Sep 12 '13 at 11:18
-
yes from webservice and using that url i want to display image on imageview. – seema Sep 12 '13 at 11:23
-
please post some format of the response so that we can give you a code – Vinodh Sep 12 '13 at 11:26
3 Answers
At the first time synchronisation store synchronisation time. And pass this time in web service in next synchronisation. So, In this response you will get only those records which will updated after last synchronisation time and only update that images. But for this you have to add time tag in your web service.

- 3,936
- 1
- 23
- 38
If the server response giving the image attribute except url for e.g. let us consider image having unique ID .Then save imageurl and image id into dictionary while saving all the image i.e.during the first download .
If server has modification then in that response you will get modified images using some of the attribute. Now store that modified image id and download them .
Ot you can you follow the SO question answered here .
iOS - Download file only if modified (NSURL & NSData)
which has the code
I ended up using this method to detect the modified date on the file: *Found on HERE
-(bool)isThumbnailModified:(NSURL *)thumbnailURL forFile:(NSString *)thumbnailFilePath{
// create a HTTP request to get the file information from the web server
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:thumbnailURL];
[request setHTTPMethod:@"HEAD"];
NSHTTPURLResponse* response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
// get the last modified info from the HTTP header
NSString* httpLastModified = nil;
if ([response respondsToSelector:@selector(allHeaderFields)])
{
httpLastModified = [[response allHeaderFields]
objectForKey:@"Last-Modified"];
}
// setup a date formatter to query the server file's modified date
// don't ask me about this part of the code ... it works, that's all I know :)
NSDateFormatter* df = [[NSDateFormatter alloc] init];
df.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
df.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
df.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
// get the file attributes to retrieve the local file's modified date
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary* fileAttributes = [fileManager attributesOfItemAtPath:thumbnailFilePath error:nil];
// test if the server file's date is later than the local file's date
NSDate* serverFileDate = [df dateFromString:httpLastModified];
NSDate* localFileDate = [fileAttributes fileModificationDate];
NSLog(@"Local File Date: %@ Server File Date: %@",localFileDate,serverFileDate);
//If file doesn't exist, download it
if(localFileDate==nil){
return YES;
}
return ([localFileDate laterDate:serverFileDate] == serverFileDate);
}
Hope this will help.
First you have to track which images are modified and than download only those.
For that you have 2 ways :
1) You can set different name of the image at server side when it will be modified and than at the time of downloading first call one webservice that lists the name of images. Than compare those names with the downloaded images name (i.e which are in your document dir). If they are different than download else not.
2) You can make local database that stores information of previously downloaded images and at the 2nd time of downloading compare those values. If different than download else not .

- 2,939
- 5
- 36
- 65