Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPhone - Get file last modified date from web server

Tags:

file

http

iphone

I want to check the last modified date on a file on a web server. Any help would be great. Thanks.

like image 481
Brian Avatar asked Sep 04 '09 18:09

Brian


2 Answers

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"];
}
like image 98
Brian Avatar answered Sep 23 '22 08:09

Brian


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];
like image 28
Muhammad Faisal Aleem Avatar answered Sep 24 '22 08:09

Muhammad Faisal Aleem