title: How to get Reachability Notifications in iOS in Background when dropping Wi-Fi network?
body: <p>I'm using Reachability successfully to determine the status of the network, and to be notified of changes (e.g. <a href="https://stackoverflow.com/questions/3790957/reachability-guide-for-ios-4">Reachability Guide for iOS 4</a>). </p>
  
  <p>My question isn't how to get Reachability up and running, but rather the following.</p>
  
  <p>My <code>AppDelegate</code> handles the Reachability stuff. The app receives notifications (<code>kReachabilityChangedNotification</code>) while the app is running, and when the app is in the Background (<code>applicationDidEnterBackground:</code>). </p>
  
  <p>The app is designed to reload a playing audio stream when it notices that it's lost a Wi-Fi connection, e.g. To test, I turned Wi-Fi on and off in Settings, and everything worked perfectly. In real-world testing, I often lose Wi-Fi connectivity when I exit the range of the access point. I've found that Reachability isn't helping me too much in this case. I'm not sure if it's because Reachability notifications don't come through when the screen is locked, or if Reachability doesn't handle the slow diminishing of signal from an increasingly distant Wi-Fi access point, but regardless I can't figure out why the real-world testing doesn't match the idealized case.</p>
  
  <p>This is what my code looks like. I first set up to receive notifications, and start listening to Reachability:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
      // check for internet connection
      [[NSNotificationCenter defaultCenter] addObserver:self 
                                               selector:@selector(checkNetworkStatus:) 
                                                   name:kReachabilityChangedNotification object:nil];
  
      // Set up Reachability
      internetReachable = [[Reachability reachabilityForInternetConnection] retain];
      [internetReachable startNotifier];    
  
      ....
  
      return YES;
  }
  </code></pre>
  
  <p>and then, this is the function that responds to changes in connectivity:</p>
  
  <pre><code>- (void)checkNetworkStatus:(NSNotification *)notice {
      // called after network status changes
  
      NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
      switch (internetStatus)
      {
          case NotReachable:
          {
              NSLog(@"The internet is down.");
              break;
          }
          case ReachableViaWiFi:
          {
              NSLog(@"The internet is working via WIFI");
              break;            
          }
          case ReachableViaWWAN:
          {
              NSLog(@"The internet is working via WWAN!");
              break;            
          }
      }    
  }
  </code></pre>
  
  <p>The notifications come through even when the app is in the background, but they don't in the real-world testing described above.</p>
  
  <p>Thanks for any help.</p>