1

In my project I am using Reachability class provided by Apple. When there is no internet connection, I am displaying an alert message. Everything is working fine, when I test it on the simulator, but when am running it on iPad, the alert message is not shown when there is no internet.

I am running the code on iOS 5.0.

Any help would be appreciated.

EDIT:

-(BOOL)isInternetConnectionPresent{

Reachability *objReachability = [Reachability reachabilityForInternetConnection];    
NetworkStatus internetStatus = [objReachability currentReachabilityStatus];

if(internetStatus != NotReachable)
{
    return YES;
}


   return NO;
}

UPDATE:

Used NSLog to debug. Seems there was some problem with WWAN, even when there was no SIM card. Restarted the iPad & switched OFF & ON the Wi Fi again. Now it works fine. Thanks for the help guys.

footyapps27
  • 3,982
  • 2
  • 25
  • 42
  • 1
    You're probably gonna get better answers if you add some more details. You could post your implementation code for example. Also try to do some debugging: some `NSLog`s at least. `Reachability` should of course work on devices, too. I use it many apps. – Rok Jarc Nov 06 '12 at 08:36
  • as i said, it works fine in simulator!!... i have edited my question to add the code. – footyapps27 Nov 06 '12 at 08:40
  • You might just have to clean the project, delete the app from device... Anyway: you'd really be better off using observer - one of best examples can be found [here](http://stackoverflow.com/a/3597085/653513) – Rok Jarc Nov 06 '12 at 09:05

2 Answers2

1

You have to check all the NetworkStatus and Cross Check the device Wifi Connection status again

Example:

// to check if, wifi connected properly in current device.
- (BOOL)networkCheck {

    Reachability *wifiReach = [Reachability reachabilityForInternetConnection];
    NetworkStatus netStatus = [wifiReach currentReachabilityStatus];

    switch (netStatus)
    {
        case NotReachable:
        {
            NSLog(@"NETWORKCHECK: Not Connected");          
            return NO;
            break;
        }
        case ReachableViaWWAN:
        {
            NSLog(@"NETWORKCHECK: Connected Via WWAN");
            return NO;
            break;
        }
        case ReachableViaWiFi:
        {
            NSLog(@"NETWORKCHECK: Connected Via WiFi");
            return YES;
            break;
        } 
    }
    return false;

}
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
0

In My case the following code snippet is working perfectly with iOS 5. Here i am checking internet connectivity with WIFI.

- (NSString *)stringFromStatus:(NetworkStatus ) status {
NSString *string;
switch(status) {
    case NotReachable:
        string = @"Not Reachable";
        break;
    case ReachableViaWiFi:
        string = @"Reachable via WiFi";
        break;
    case ReachableViaWWAN:
        string = @"Reachable via WWAN";
        break;
    default:
        string = @"Unknown";
        break;
}
return string;

}

------------------------ now with following line of code you can check.

 Reachability *reach =[Reachability reachabilityForLocalWiFi] ;
NetworkStatus status = [reach currentReachabilityStatus];
NSLog(@"%@", [self stringFromStatus: status]);

if ([[self stringFromStatus: status] isEqualToString: @"Not Reachable"]) 
{
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Connection Failure !"
                          message:@"Your Device is not Connected to any active WIFI Connection."
                          delegate:self
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];
}
else
{ //connected to internet.

}

Black Tiger
  • 1,201
  • 11
  • 12