title: IOS/Objective-C: Fastest way to check for Internet connection - 2017
body: <p>My code for checking for an Internet connection, I discovered yesterday on an airplane, is excruciatingly slow.  I am using the technique in many older <a href="https://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-ios-or-osx">SO answers</a> of checking an NSUURL, however, it literally took fifteen seconds or more to return FALSE when on an airplane with no connectivity making the app essentially unusable.  </p>
  
  <p>Is there a dependable asynchronous method that would do this? People recommend Tony Million's reachability class in older answers but it seems very complicated and Apple is apparently rejecting some apps <a href="https://github.com/tonymillion/Reachability" rel="nofollow noreferrer">using it</a>.  Would appreciate it if someone could suggest the fastest, reliable way to check Internet connection in 2017.  Thank you.</p>
  
  <pre><code>- (BOOL)connected
      {
          NSURL *scriptUrl = [NSURL URLWithString:@"https://www.google.com"];
          NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
          if (data) {
              NSLog(@"Device is connected to the internet");
              return TRUE;
          }
          else {
              NSLog(@"Device is not connected to the internet");
              return FALSE;
          }
      }
  </code></pre>