0

In need to check if the phone is connected to the internet.

I currently implemented this check as followed:

NSString *connectionString = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/ncr"] encoding:NSUTF8StringEncoding error:nil];

//If user isn't connected
if ([connectionString length] == 0){
    //Do this
} else {
    //Do that
}

This check works perfectly on WIFI networks! But as soon as the user is on a 3G / EDGE network the connectionString = null

How can I improve this check, even on 3G networks?

Thanks

Alex van Rijs
  • 803
  • 5
  • 17
  • 39
  • See http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk it might help you. – 4ndrew Dec 14 '11 at 10:59

1 Answers1

2

Apple has made a great class for doing this: Reachability.

It can tell you wether you are connect to WiFi or WAN (3G and GRPS).

rckoenes
  • 69,092
  • 8
  • 134
  • 166