Reputation: 145
how to check internet connection through iphone or objective-c.???
Upvotes: 0
Views: 211
Reputation: 1039
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];
}
Upvotes: 2
Reputation: 3847
Have a look at the apple sample code Reachability. It should provide you with everything you need.
Upvotes: 0
Reputation: 59689
Apple's recommendation is to do something like (or use) Reachability
Upvotes: 0