Hi
How do I check internet connection in cocoa application? Can Reachability code from iphone apple example be reused for this purpose?
Thanks,
Nava
Hi
How do I check internet connection in cocoa application? Can Reachability code from iphone apple example be reused for this purpose?
Thanks,
Nava
This code will help you to find if internet is reachable or not:
-(BOOL)isInternetAvail
{
BOOL bRet = FALSE;
const char *hostName = [@"google.com" cStringUsingEncoding:NSASCIIStringEncoding];
SCNetworkConnectionFlags flags = 0;
if (SCNetworkCheckReachabilityByName(hostName, &flags) && flags > 0)
{
if (flags == kSCNetworkFlagsReachable)
{
bRet = TRUE;
}
else
{
}
}
else
{
}
return bRet;
}
For more information you can look at the iphone-reachability
Apple has a nice code which does it for you. You can check if your connection is WiFi for instnace or just cell/WiFi. link text