title: Detecting Network Connectivity Changes using Reachability, NSNotification and Network Link Conditioner in Swift
body: <p>From iOS 12 you simply use <strong>NWPathMonitor</strong> which is a line of code (<a href="https://www.hackingwithswift.com/example-code/networking/how-to-check-for-internet-connectivity-using-nwpathmonitor" rel="noreferrer">example</a>).</p>
  
  <p>For historic purposes:</p>
  
  <hr>
  
  <p>I'm trying to integrate <strong>network connectivity</strong> detection into my app, however it seems that somewhere along the line I have made a mistake as my network changes are not being detected/printed out into the console.</p>
  
  <p>As mentioned in the post, I'm currently using these following classes and tools for the job:</p>
  
  <ol>
  <li>Reachability <code>{.h, .m}</code> </li>
  <li><code>NSNotificationCenter</code></li>
  <li>Network Link Conditioner</li>
  </ol>
  
  <p><strong>Code</strong></p>
  
  <p>In the <strong>AppDelegate.Swift</strong>, I've set up the <code>NSNotificationCenter</code> to detect changes:</p>
  
  <pre><code>func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
  // ... 
  // A: Checks if the device is connected to the internet
  
      var defaultCenter: Void = NSNotificationCenter().addObserver(self, selector:"checkForReachability", name: kReachabilityChangedNotification, object: nil)
  </code></pre>
  
  <p>} </p>
  
  <p>In the same class <code>AppDelegate</code>, I've also created this function to be triggered whenever there is a change: </p>
  
  <pre><code>func checkForReachability () {
  
      var networkReachability = Reachability.reachabilityForInternetConnection()
      networkReachability.startNotifier()
  
      var remoteHostStatus = networkReachability.currentReachabilityStatus()
      if (remoteHostStatus.value == NotReachable.value) {
          println("Not Reachable")
      } else if (remoteHostStatus.value == ReachableViaWiFi.value) {
          println("Reachable via Wifi")
      } else {
          println("Reachable")
      }
  }
  </code></pre>
  
  <p>However, when using the Network Link Conditioner to manipulate and simulate changes in conditions, I haven't been able to see any of those changes reflected in the console. Any help would be swell!</p>