hoya21
hoya21

Reputation: 893

Waiting into controller until wifi enabled IOS

I have a controller in my app that needs internet connection to run. I know what i have to do if device has or not internet connection before the app begins. Although i have stucked with the issue that the user must enable internet connection into app. I have a method that checks if there is internet connection and if not it shows an alert view. I want to retain to this view controller until internet enabled. Here is the code of my function that is not working. Any advice are welcome.

- (void) checkIfInternetEnabled{

    Reachability *hostReach = [Reachability reachabilityWithHostName: @"www.apple.com"] ;

    NetworkStatus netStatus = [hostReach currentReachabilityStatus];

    if (netStatus != ReachableViaWiFi){

        NSLog(@"oooaoaoaolaoeworolaowoeoal");

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"You must enable wi-fi the first time that you use the application for complete installation " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alert show];

        netStatus = [hostReach currentReachabilityStatus];

        while(netStatus!= ReachableViaWiFi){

            [alert show];

            netStatus = [hostReach currentReachabilityStatus];

        }

    }

}

Upvotes: 0

Views: 435

Answers (1)

Nikos M.
Nikos M.

Reputation: 13783

You should listen to the notifications that reachability class sends about network status changes (you should use reachability 2.x):

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reachabilityChanged:)
                                             name:kReachabilityChangedNotification
                                           object:nil];

Upvotes: 3

Related Questions