Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:32:43+00:00 2026-06-14T17:32:43+00:00

The purpose of my code is to compare the modification dates of a server

  • 0

The purpose of my code is to compare the modification dates of a server file and a local file, in case that the server file is newer, it will download it.

My first attempt was to use a synchronous request using the code from http://iphoneincubator.com/blog/server-communication/how-to-download-a-file-only-if-it-has-been-updated

But it didn’t worked.
After that I’ve been struggling to find the solution, tried asynchronous request, tried different codes I found around stackoverflow, google, etc. but nothing works.

If in terminal I do curl -I <url-to-file> I get the header values so I know is not a server problem.

This is the code I’m struggling with right now (It’s written in Appdelegate.m)

- (void)downloadFileIfUpdated {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url
                                                       cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
                                                   timeoutInterval: 10];
[request setHTTPMethod:@"HEAD"];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
  if(!connection) {
    NSLog(@"connection failed");
  } else {
    NSLog(@"connection succeeded");
  }
}



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self downloadFileIfUpdated]
}



#pragma mark NSURLConnection delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSString *lastModifiedString = nil;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
  if ([response respondsToSelector:@selector(allHeaderFields)]) {
    lastModifiedString = [[response allHeaderFields] objectForKey:@"Last-Modified"];
  }
  [Here is where the formatting-date-code and downloading would take place]
}

Right now, as it is, it gives me the error No visible @interface for 'NSURLResponse' declares de selector 'allHeaderFields'.

When I use the synchronous approach the error is that NSLog(@"%@",lastModifiedString)returns (null).

PS: If there is a better way I can explain myself or the code, please let me know.

UPDATE

The URL I’m using is of type ftp://and that may be the problem of why I don’t get any HEADERS. But I can’t figure out how to do it then.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:32:43+00:00Added an answer on June 14, 2026 at 5:32 pm

    Change your code to this… in the ‘if’ conditional, you were checking response instead of httpResponse:

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSString *lastModifiedString = nil;
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
      if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) {
        lastModifiedString = [[httpResponse allHeaderFields] objectForKey:@"Last-Modified"];
      }
      // [Here is where the formatting-date-code and downloading would take place]
    }
    

    … and once you feel comfortable that the response is going to always be an NSHTTPURLResponse, you could probably just get rid of the conditional statement:

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
      NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
      NSString *lastModifiedString = [[httpResponse allHeaderFields] objectForKey:@"Last-Modified"];
      // [Here is where the formatting-date-code and downloading would take place]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The purpose of this code is to pull upgrade.zip from a central server, extract
What is the purpose of the code behind view file in ASP.NET MVC besides
I've got following (simplified for example purpose) code and it works: void log(const string
Quick question, What have I done wrong here. The purpose of this code is
Suppose i have the code snippet as follows : ( clarification purpose/not well formed
What is the purpose of these java.lang.annotation imports in this code? Why are they
One recommends me the following code apparently only in .zshrc without explaining its purpose
What is the main purpose of overloading operators in C++? In the code below,
I run the following code on a Windows platform. The purpose is the know
I am not sure about the exact purpose of the following Rampion's code .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.