0

how to check internet connection through iphone or objective-c.???

user177893
  • 137
  • 1
  • 10
  • Similar: http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk – miku Nov 26 '09 at 10:52
  • Duplicate of http://stackoverflow.com/questions/1802592/internet-problem/1802657 – Lee Nov 26 '09 at 11:02

4 Answers4

2

Here is a code snippet you can use:

[[Reachability sharedReachability] setHostName:@"example.com"];
if ([[Reachability sharedReachability] remoteHostStatus] == NotReachable) {
    UIAlertView *dialog = [[[UIAlertView alloc] init] retain];
    [dialog setTitle:@"Server unreachable"];
    [dialog setMessage:@"The server is temporarily unavailable."];
    [dialog addButtonWithTitle:@"OK"];
    [dialog show];
    [dialog release];
}
Vincent Osinga
  • 1,037
  • 7
  • 15
0

Quick and Drity: Ping Google?

Bobby
  • 10,998
  • 5
  • 42
  • 67
0

Apple's recommendation is to do something like (or use) Reachability

prakash
  • 55,001
  • 25
  • 87
  • 114
0

Have a look at the apple sample code Reachability. It should provide you with everything you need.

Mick Walker
  • 3,772
  • 6
  • 44
  • 70