sharon
sharon

Reputation: 580

Reachability status message appears only once

I am popping a message alerting the user that he/she has lost WIFI/intenet connection. For that, i followed the Reachability example given by apple.

I added the 2 reachability classes, Rechability.h and .m, and i added the codes given in its app delegate to mine as well (an exact replica). This works perfectly.

My problem is that, this message appears only once, i want it to be displayed when it goes to each and every view.

All codes that i am using can be found here. Help

Upvotes: 0

Views: 128

Answers (3)

Giuseppe Garassino
Giuseppe Garassino

Reputation: 2292

Mmm... Not sure to understand what you expect Rechability does.

This class is designed to get any change in your rechability status. When a change is detected Reachability send a notification, but if nothing changes you won't get any notification.

EDIT: to get your reachability status and to use it later you can add a BOOL (internetIsDown) to the method where you read notification from Reachability.

- (void)checkNetworkStatus:(NSNotification *)notice {
    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
    switch (internetStatus) {
        case NotReachable: {
            internetIsDown = YES;
            break;
        } case ReachableViaWiFi: {
            internetIsDown = NO;
            break;
        } case ReachableViaWWAN: {
            internetIsDown = NO;
            break;
        }
    }
}

Now you can check for this BOOL value whenever needed and display an alert to the user.

N.B. internetIsDown should be a singleton if you want to access its value from any viewController!!!

Upvotes: 1

Keller
Keller

Reputation: 17081

You could call [Reachability reachabilityForInternetConnection] in each view's viewDidAppear method...

But like others have mentioned, it could be kind of annoying to see the same message over and over.

Upvotes: 1

Johan Karlsson
Johan Karlsson

Reputation: 1137

I have an application where I have tabs. The root controller registers for reachability messages. An UIAlertView is used to display a warning. This is shown in all parts of the application.

Upvotes: 1

Related Questions