Page Banner

Reachability iOS Software Development

The Reachability class can be used to check the network connectivity of an iOS device. It uses the System Configuration framework to monitor the network state of an iOS device. However Reachability cannot tell your application whether it is connected to a specific WIFI network or WLAN.

Apple provides the headers for reachability class which can be downloaded from the Apple Developer website.

In order to implement reachability in your application, do the following:

1. First, download the files (reachability.h and reachability.m) into your project.

2. Add the SystemConfiguration.framework into your project.

3. Import Reachability.h file into your class.

4. The following code can be used to check the connectivity you have on your device.

Make an instance of Reachability and start looking for any network connectivity

Reachability *reachability =

        [Reachability reachabilityForInternetConnection];

    [reachability startNotifier]; //Start looking for network changes

   

    NetworkStatus networkStatus =

        [reachability currentReachabilityStatus];

   

    if(networkStatus == NotReachable) {

        NSLog(@”No Internet”);

    }

    else if (networkStatus == ReachableViaWiFi) {

        NSLog(@”Wi-Fi”); // If network connection is WIFI

    }

    else if (networkStatus == ReachableViaWWAN) {

        NSLog(@”3G”); // If network connection is WWAN

    }

    [reachability stopNotifier]; //stop looking for network changes