I want to check the last modified date on a file on a web server. Any help would be great. Thanks.
Asked
Active
Viewed 2,676 times
3 Answers
6
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:aURL];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
if( [response respondsToSelector:@selector( allHeaderFields )] )
{
NSDictionary *metaData = [response allHeaderFields];
NSString *lastModifiedString = [metaData objectForKey:@"Last-Modified"];
}

Brian
- 3,571
- 7
- 44
- 70
3
This will first download the whole file from the server. I have modified the code myself in order to just get the header info. Here's the code
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlString cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
[request setHTTPMethod:@"HEAD"];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
if( [response respondsToSelector:@selector( allHeaderFields )] )
{
NSDictionary *metaData = [response allHeaderFields];
NSString *lastModifiedString = [metaData objectForKey:@"Last-Modified"];
NSLog(@"Date = %@",lastModifiedString);
}
[request release];
-
This is a better solution for all who only want to have the last modified date. – AlexVogel Mar 18 '15 at 12:21
0
You can have the CMS write a file containing a date of modification. You can then download that file using a number of [:initWithURL] methods. Compare that date to the whatever stored date that you have.
I suppose you can also ftp the desired file. Then use NSFileManager to look at properties of the file, NSString *NSFileModificationDate will give you a date that you can compare with whatever stored date you want.
You can search SO for ftp solutions.

Jordan
- 21,746
- 10
- 51
- 63