How to check for Network Connectivity in iOS

What you really want is a method such as (BOOL)networkIsAvailable, returning YES or NO. Apple made it several megabytes long and requires you to study several years before you get to YES or NO.

I hate that! This is such a basic function on an always-connected device that I find it appalling not to have this available to all developers without hassle at all times.

Apple do give us some example code called Reachability in their documentation, which – like so many things – is hopelessly outdated and doesn’t work with ARC anymore: http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

Thank god for the wonderful Tony Million who has updated the project and made it available on GitHub: https://github.com/tonymillion/Reachability – works with ARC and everything. It’s a simple drop-in class, exactly what we all want and need.

I salute you, Tony! Thank you very much ;-)

Here’s how to add it to your project step by step:

  1. add both Reachability.h and Reachability.m to your project
  2. add the SystemConfiguration.framework to your project
  3. in the class that needs to check for network connectivity, #import Reachability.h
  4. create a method such as this to check which network connection you’ve got:

Obviously check which host you’d like to reach. There are several other methods in this class, such as reachabilityForInternetConnection. Check out Tony’s examples on GitHub for more:

https://github.com/tonymillion/Reachability

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!