I use the following method in my project
-(NSArray*)networkErrorCodes { static NSArray *codesArray; if (![codesArray count]){ @synchronized(self){ const int codes[] = { //kCFURLErrorUnknown, //-998 //kCFURLErrorCancelled, //-999 //kCFURLErrorBadURL, //-1000 //kCFURLErrorTimedOut, //-1001 //kCFURLErrorUnsupportedURL, //-1002 //kCFURLErrorCannotFindHost, //-1003 kCFURLErrorCannotConnectToHost, //-1004 kCFURLErrorNetworkConnectionLost, //-1005 kCFURLErrorDNSLookupFailed, //-1006 //kCFURLErrorHTTPTooManyRedirects, //-1007 kCFURLErrorResourceUnavailable, //-1008 kCFURLErrorNotConnectedToInternet, //-1009 //kCFURLErrorRedirectToNonExistentLocation, //-1010 kCFURLErrorBadServerResponse, //-1011 //kCFURLErrorUserCancelledAuthentication, //-1012 //kCFURLErrorUserAuthenticationRequired, //-1013 //kCFURLErrorZeroByteResource, //-1014 //kCFURLErrorCannotDecodeRawData, //-1015 //kCFURLErrorCannotDecodeContentData, //-1016 //kCFURLErrorCannotParseResponse, //-1017 kCFURLErrorInternationalRoamingOff, //-1018 kCFURLErrorCallIsActive, //-1019 //kCFURLErrorDataNotAllowed, //-1020 //kCFURLErrorRequestBodyStreamExhausted, //-1021 kCFURLErrorFileDoesNotExist, //-1100 //kCFURLErrorFileIsDirectory, //-1101 kCFURLErrorNoPermissionsToReadFile, //-1102 //kCFURLErrorDataLengthExceedsMaximum, //-1103 }; int size = sizeof(codes)/sizeof(int); NSMutableArray *array = [[NSMutableArray alloc] init]; for (int i=0;i<size;++i){ [array addObject:[NSNumber numberWithInt:codes[i]]]; } codesArray = [array copy]; } } return codesArray; }
Then I just check the error code and show a warning if it is in the list
if ([[self networkErrorCodes] containsObject:[NSNumber numberWithInt:[error code]]]){
But, as you can see, I commented on codes that, it seems to me, do not match my definition of NO INTERNET. For example, code -1012 (Authentication Error). You can edit the list as you wish.
In my project, I use it when entering a username and password from a user. And in my opinion, a (physical) network connection may be the only reason to show a warning in a network-based application. In any other case (for example, an incorrect pair of user / password words), I prefer to do some kind of user-friendly animation, OR just retry the failed attempt again without any user attention. Especially if the user has not explicitly initiated a network call.
Regarding martinezdelariva for reference to documentation.