Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tony million Reachability says unreachable when connected

I have searched but have not found an issue like mine. I'm sure it's something I have over looked .

I am using tony million's reachability block method. it is working good when i have internet then no internet. the alert comes up and works just fine.

but, when i have no internet and then i get internet the same alert pops up

my code is

-(void)reachabilityBlock
{
// allocate a reachability object
Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"];

// tell the reachability that we DONT want to be reachable on 3G/EDGE/CDMA
reach.reachableOnWWAN = YES;


reach.reachableBlock = ^(Reachability * reachability)
{
    dispatch_async(dispatch_get_main_queue(), ^{
        //NSLog(@"REACHABLE! block");
        [self newsTableViewRefresher];
    });
};

reach.unreachableBlock = ^(Reachability * reachability)
{

        dispatch_async(dispatch_get_main_queue(), ^{
            //NSLog(@"UNREACHABLE! block");

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"No Network found!"
                                                            message: @"You have no wifi or cellular connection available. Please connect to a WIFI or cellular network."
                                                           delegate: self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];

            [alert show];


        });

};


[reach startNotifier];
[self.refreshControl endRefreshing];

 }

my question is why when i get internet does the unreachable alert pop up?

thank you for your time

like image 971
user1184205 Avatar asked Oct 14 '13 19:10

user1184205


1 Answers

This is what I did on my end and got the job done for me. I try using the blocks but it seems it was more trouble that solving my issue. Hope this helps.

Reachability *reach = [Reachability reachabilityWithHostname:@"www.jportdev.com"];
if ([reach isReachable]){
    // Reachable
    //NSLog(@"is reachable.......");
}else{
    // not Reachable
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network is unavaliable!" message:@"Some content in this application might not be avaliable without network connectivity." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    alert = nil;
}
like image 87
Jiraheta Avatar answered Oct 27 '22 11:10

Jiraheta