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 pos开发者_StackOverflow中文版sible to check internet connection in Iphone? Any suggestion for this issue?
Really appreciate for any suggestions, comments and guides.
Thanks.
Apple has a commonly used sample for this, Reachability isn't that bad to use, and will show you the path to go down.
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
Best to use Reachability......
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!!
精彩评论