Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to test if a file at an external URL exists without downloading it?
    text
    copied!<p>I would like to test if a URL exists without loading any actual data.</p> <p>I was thinking of initiating a NSURLConnection, and then using these two delegate methods to check the status:</p> <pre><code>- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { // Connection failed ... presumably this is a server issue, and I don't know if the URL exists or not. } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { int status = [((NSHTTPURLResponse *)response) statusCode]; [connection cancel]; // Do something with the status } </code></pre> <p>Would this be a sensible way? The files I'm testing could potentially be very large, so I want to make sure that the actual file is not downloaded.</p> <p>Thanks, Ron</p> <p>p.s. I'm looking at adding this because Apple forced my App to stop backing up files downloaded from the internet. Instead, I store the files in non-backed up space, and in my backed up database I keep track of the original location of the file. Since the file is intended to be a permanent part of the user's library, I would like to periodically test if a file is not accessible and then move it into backed up space (so it will survive a restore to a new device, for example). I'm very annoyed at Apple for forcing me to make this change as I can imagine customers losing important data.</p> <p>p.p.s. For some strange reason, these delegate methods no longer appear in the documentation for NSURLConnectionDelegate Protocol. I'm assuming the documentation is just messed up.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload