Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does NSURLConnection's error code "-1009" mean?

When I send a request and get an error with the error code -1009, what does that mean? I'm not sure how to handle it.

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
      NSLog(@"connection didFailWithError");

   if(error.code==-1009){       
      //do something           
   }    
}
like image 938
jxx Avatar asked Jul 14 '11 06:07

jxx


People also ask

What does code 1009 mean?

If you experience the error code 1009, it typically points to information stored on your device that needs to be refreshed.

What causes Nsurlerrorcancelled?

A requested resource couldn't be retrieved. An attempt to establish a secure connection failed for reasons that can't be expressed more specifically. A server certificate is expired, or is not yet valid. A server certificate wasn't signed by any root server.

How do I fix Nsurlerrordomain error?

You might see this error message if you are running an outdated version of the NetUpdate application on your Mac. To resolve the issue, simply download and install the latest version of NetUpdate. Now, restart your computer and NetUpdate should work again as expected.


3 Answers

Since the error returned should be within the NSURLErrorDomain, the code -1009 means:

NSURLErrorNotConnectedToInternet

Returned when a network resource was requested, but an internet connection is not established and cannot be established automatically, either through a lack of connectivity, or by the user's choice not to make a network connection automatically.

like image 146
DarkDust Avatar answered Sep 21 '22 06:09

DarkDust


With Swift, you can use the NSURLError enum for NSURL error domain check:

switch NSURLError(rawValue: error.code) {
case .Some(.NotConnectedToInternet):
    print("NotConnectedToInternet")
default: break
}

Swift 3:

switch URLError.Code(rawValue: error.code) {
case .some(.notConnectedToInternet):
    print("NotConnectedToInternet")
default: break
}

Swift 4:

switch URLError.Code(rawValue: error.code) {
case .notConnectedToInternet:
    print("NotConnectedToInternet")
default: break
}
like image 40
ricardopereira Avatar answered Sep 19 '22 06:09

ricardopereira


It's NSURLErrorNotConnectedToInternet which means, well, that you're not connected to the internet... :)

You can find the error codes in NSURLError.h.

like image 43
Morten Fast Avatar answered Sep 19 '22 06:09

Morten Fast