0

I have a code to detect if I have internet connection or not, and sometimes it doesn't work well. Here's the code:

-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"Error" message:@"Couldn't connect to the Internet. Please check your connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];   
    [alert show];
    [alert release];
}

The problem is that sometimes a web doesn't load for other things and not because it has a bad connection. I hope that there's a better way to check the WiFi. Any idea?

WrightsCS
  • 49,871
  • 22
  • 132
  • 180
Adri
  • 243
  • 3
  • 12
  • Internet conniption, eh? – p.campbell Feb 20 '12 at 20:00
  • 6
    possible duplicate of [How to check for an active Internet Connection on iPhone SDK?](http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk) – jscs Feb 20 '12 at 20:00
  • you can check for WiFi connectivity and even for host reachability - check the link Josh gave you – Rok Jarc Feb 20 '12 at 20:02
  • Sorry, I don't know why I have written conniption... I think it has been the auto-corrector of OS X... Sometimes it does strange things... – Adri Feb 20 '12 at 20:11
  • 1
    Sorry, but I'm not seeing any code that checks for an internet connection, just code that shows an Alert. – crashmstr Feb 20 '12 at 20:24
  • I think your confusing the Notification Alert with Alert Views. That code looks great and is just what you need. – Darren Feb 20 '12 at 21:47

1 Answers1

3

I suggest you follow the link and read the best marked answer given in there. It worked perfectly with me. How to check for an active Internet connection on iOS or OSX?

Community
  • 1
  • 1
Guy Daher
  • 5,314
  • 5
  • 36
  • 64