How to check Internet Reachability and name of Wifi network.
It has always been a required feature to check weather the device is connected to internet or not. Everyone of us look for internet connection first whenever we find delay in getting response in an application. In this blog we will learn how to check for Internet Connection and also get the name of WIFI network to which your IOS device is currently Connected.
Open Xcode and Create a single View Application, save it and named it Like “Reachability Demo”.
Import system Configuration framework and Reachability class.
The Reachability class depends on the System Configuration framework for some of its functionality. With your project selected in the Project Navigator, open the Build Phases tab, and expand the Link Binary with Libraries drawer. Click the plus button and search for SystemConfiguration.framework and add it to your project.
To get the Reachability classes, Visit the project’s GitHub page, download the latest version, and drag Reachability.h/.m into your Xcode project (figure 3). If you take this path, make sure to copy the class files into your Xcode project (figure 4). You can also use CocoaPods to to add Reachability to your project.
Import framework in your controller
In your view controller.m class import the system framework and Reachability.h class.
Check Internet Reachability
In your Viewdidload method add the following code to first check whether there is any internet connection available or not and also the type of connection your device is connected with.
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable)
NSLog(@"Please check your network connection");
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == NotReachable)
else if (status == ReachableViaWiFi)
//Connected to WiFi
else if (status == ReachableViaWWAN)
//Connected to 3G
Above code checks for the internet connection and if connection found then it shows wether the device is connected to wifi network or WWAN.
Get WIFI network name
To get wifi network name add the below given code in the part where it shows that device is connected to wifi. Please refer the below mentioned code and screenshot given.
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
// NSLog(@"SSID: %@",CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID));
NSString *networkName = CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID);
NSLog(@"%@ show network name",networkName);
Run your application on device and in application console check what network name your device is connected with.
Hope it was an easy post on Internet Reachability Check in iOS Objective C and to get WIFI network name. I’l be back in my next blog with something very interesting, till then happy coding ;).