1

So I make alert view detects if there in a active internet connection.

This is the Code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(reachabilityChanged:)
    name:kReachabilityChangedNotification
    object:nil];
    Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"];
    reach.reachableBlock = ^(Reachability * reachability)
    { 
     dispatch_async(dispatch_get_main_queue(), ^{
     blockLabel.text = @"";  
     });
    };
    reach.unreachableBlock = ^(Reachability * reachability)
    {
     dispatch_async(dispatch_get_main_queue(), ^{
     blockLabel.text = @"You are not connected to the Internet";
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please connect to Internet"
     message:nil
     delegate:self
     cancelButtonTitle:nil
     otherButtonTitles:nil];
     UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
     progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
            [alert addSubview:progress];
            [progress startAnimating];
            [alert show]; 
        });
    };
    [reach startNotifier];
    // Do any additional setup after loading the view, typically from a nib.
}

So my application detects if there is a internet connection. But the issue is that if I turn on internet on the iPhone and open the application it still saying there is not internet connection. What should I do…

Programmer...
  • 481
  • 6
  • 28
  • I have a quick question how to disable the alert view when connected to internet…. – Programmer... Nov 22 '12 at 20:23
  • when you are using third party classes you might as well state it if anyone is to make any sense of your code, it looks like https://github.com/tonymillion/Reachability in this case – valexa Nov 22 '12 at 23:01
  • Check this answer http://stackoverflow.com/questions/12589042/apple-reachability-notifications-for-network-or-wi-fi – user1509593 Nov 25 '12 at 13:05

3 Answers3

1

Well i fix the issue by using notifications.. Code for Reference

-(void)reachabilityChanged:(NSNotification*)note
{
    Reachability * reach = [note object];

    if([reach isReachable])
    {
        notificationLabel.text = @"Notification Says Reachable";
        NSLog(@"Internet is Up");
    }
    else
    {
        notificationLabel.text = @"Notification Says Unreachable";
        NSLog(@"Internet is Down");
    }
}
Programmer...
  • 481
  • 6
  • 28
0

You could always implement a non-stop checking for host reachability (or internet connectivity) by signing up for reachability notifications.

One of best examples on how to do this can be found here on SO: How to check for an active Internet Connection on iPhone SDK?

This way your app will always know if the host is reachable or not.

Community
  • 1
  • 1
Rok Jarc
  • 18,235
  • 9
  • 64
  • 120
0

There is no telling what your sparse code does as it does not even look like your Reachability class is Apple's Reachability sample code wrapper around the SystemConfiguration API , you can find that at http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

The simplest and most definitive check is just a uncached NSURLRequest for a specific url (not just a hostname which merely tests if DNS resolution is working which is not a definitive test and could even be cached)

valexa
  • 4,245
  • 28
  • 48