39

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           
   }    
}
jscs
  • 63,694
  • 13
  • 151
  • 195
jxx
  • 405
  • 1
  • 4
  • 6

3 Answers3

75

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.

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224
21

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
}
ricardopereira
  • 11,118
  • 5
  • 63
  • 81
8

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

You can find the error codes in NSURLError.h.

Morten Fast
  • 6,322
  • 27
  • 36