Unable to fire network change event

My iphone application is pretty simple with one view that handles everything, in viewDidLoad I check if we have an internet connection, and if we download from the Internet, and if we do not download it from a local resource. And it works great.

//in viewDidOnload    
[[NSNotificationCenter defaultCenter] addObserver:self 
                                          selector:@selector(handleNetworkChange:) 
                                          name:kReachabilityChangedNotification object:nil];
reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];

if (status == NotReachable) {
    //Do something offline
} else {
    //Do sometihng on line
}

- (void)handleNetworkChange:(NSNotification *)notice{
 NetworkStatus status = [reachability currentReachabilityStatus];
 if (status == NotReachable) {
  //Change to offline Message
 } else {
  //Relaunch online application
 }

}

To check the handleNetworkChange event, I turned off all cellular data, but turned off Wi-Fi. In the Wi-Fi range, I started the application and everything works fine. Then I go beyond the wifi range, but my handleNetworkChange never fires (tested using uiAlertView). Standing outside the Wi-Fi range, my app launches an offline message just fine.

, ViewController, AppDelegate? , .

+5
4

, , , , , dealloc stopNotifier. , , .

, :

reachability = [Reachability reachabilityForInternetConnection];

reachability = [[Reachability reachabilityForInternetConnection] retain];

!

, , , , "". .:)

+18

Apple. , AppDelegate. , AppDelegate, IsConnected bool.

... , , . DidFail NSUrlConnection UIWebView, , . , , , , - , .

, !

0

systemconfiguration.framework .

-1
source

Your application does not work in the background.

Add this method to the delegate class

- (void)applicationDidEnterBackground:(UIApplication *)application
{ UIApplication* app = [UIApplication sharedApplication];

    UIBackgroundTaskIdentifier __block bgTask = [app beginBackgroundTaskWithExpirationHandler: ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [app endBackgroundTask:bgTask];
            bgTask = UIBackgroundTaskInvalid;
        });
    }];

}

thank

-2
source