Reputation: 41
I need to develop an Iphone application which need to know whether the Iphone is connected to internet. If yes, I need load some data from server.
So, is it possible to check internet connection in Iphone? Any suggestion for this issue?
Really appreciate for any suggestions, comments and guides.
Thanks.
Upvotes: 2
Views: 1666
Reputation: 2983
Best option is to use Reachability.
You can put a checkmark when you are loading some data from the web(or anywhere) each and everytime.
-(void)checkInternetConnection
{
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
internetStatus = [r currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network."delegate:self cancelButtonTitle:@"Ok"otherButtonTitles:nil];
[myAlert show];
[myAlert release];
return;
}
}
You can simply call this method everytime.
Hope it helps!!
Upvotes: 0
Reputation: 9423
May want to look at if(navigator.onLine) { onlineCode() }
, HTML5 feature and iPhone supports HTML5.
also look into this on SO
Checking online status from an iPhone web app
Upvotes: 0
Reputation: 28688
Apple has a commonly used sample for this, Reachability isn't that bad to use, and will show you the path to go down.
Upvotes: 5