Question

I'm using this library to get notified when the connection status on the device changes. I don't understand WHY this is not working! I'm doing exactly what I'm reading in the documentation in github!

When the app starts, the notification gets posted but when I open the settings, turn on/off airplane mode and go back to the app (without closing it) the notifiation does not get called.

I have also subscribed to get the UIApplicationWillEnterForegroundNotification notifications... both methods DO EXISTS in the app... am I missing something?!?

This is in my viewDidLoad:

self.reach = [Reachability reachabilityWithHostname:kServerURL];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reachabilityChangedInApp:)
                                             name:kReachabilityChangedNotification
                                           object:nil];
[self.reach startNotifier];

[[NSNotificationCenter defaultCenter] addObserver:self
                                        selector:@selector(initializeDateRelatedStuff:)
                                            name:UIApplicationWillEnterForegroundNotification
                                          object:nil];

This is in my dealloc

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

Thanks!!

Was it helpful?

Solution

The thing is that your application is most likely not a background application and thus suspended once you press the home button to activate airplane mode. Since your app is not running when the reachability changes, it won't get any notification. You will get the notification, however, when network reachability changes while your app is in foreground.

So you probably want to check the reachability when your app enters the foreground in addition to what you have already implemented.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top