hi I’m trying check internet connection in my application. so for that i have already imported the reachability h file and m file in project. I’m getting some issues with that now. its working only if internet connection available its not working in without the net connection..
here this is the code which have used..
-(BOOL)reachable {
Reachability *reach = [Reachability reachabilityWithHostName:@"https://www.google.co.in/"];
NetworkStatus internetStatus = [reach currentReachabilityStatus];
if(internetStatus == NotReachable) {
UIAlertView *alertOne = [[UIAlertView alloc]initWithTitle:@"Internet" message:@"You dont have internet connection to send message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
[alertOne show];
[alertOne release];
}
return YES;
}
i have already used this same code in other projects its working their but here its showing the alert message when internet connected its not showing when its not connected ...
this viewdidload code...
[super viewDidLoad];
[self reachable];
pls can any tell me how to resolve this...
thanks
Try below code
Reachability *reach = [Reachability reachabilityForInternetConnection];
//(or)
Reachability *reach = [Reachability reachabilityWithHostName:@"http://www.google.com"];
NetworkStatus netStatus = [reach currentReachabilityStatus];
if (netStatus != NotReachable)
{
//Reachable ..Network connection is available
}
else
{
//NSLog(@"Network Error No Network Available ");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"Please connect to an Internet connection to Register" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil , nil];
[alertView show];
}
It works for you...