I need to determine if Internet Connection is available or not. I don\'t care how it is connected (WI-FI, Lan,etc..) . I need to determine, is Internet Connection available
One way to do it is :
// Check whether the user has internet
- (bool)hasInternet {
NSURL *url = [[NSURL alloc] initWithString:@"http://www.google.com"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0];
BOOL connectedToInternet = NO;
if ([NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]) {
connectedToInternet = YES;
}
//if (connectedToInternet)
//NSLog(@"We Have Internet!");
[request release];
[url release];
return connectedToInternet;
}