Check Network Availability in IOS Application

Check the internet availability in IOS application using Reachability Plugin.
A sample demonstration plugin is attached here.
The Reachability sample demonstrates the asynchronous use of the SCNetworkReachability API. You can use the API synchronously, but do not issue a synchronous check by hostName on the main thread. If the device cannot reach a DNS server or is on a slow network, a synchronous call to the SCNetworkReachabilityGetFlags function can block for up to 30 seconds trying to resolve the hostName. If this happens on the main thread, the application watchdog will kill the application after 20 seconds of inactivity.

Follow the steps to use a simple network check in application

Step 1: Import “Reachability.h” file in the header file of your viewController

#import "Reachability.h"

Step 2: Add the following code in the area of your file where you need to check the network availability

Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
    if (networkStatus == NotReachable) {
        NSLog(@"No network is available");
    } else {
        NSLog(@"Network is available");
    }

Here the function will check the current network availability, and will log it in the console.

Place the desired function in the area, according to the requirement.

Download the sample project

Leave a Comment

DON’T MISS OUR GIVEAWAYS!
Subscribe To Newsletter
Subscribe to our newsletter and get all the latest updates offers and giveaways right in your inbox.
Subscribe
Give it a try, you can unsubscribe anytime.
close-link
LIKE OUR FACEBOOK PAGE

GIVEAWAY

Like & Win
LIKE NOW
* Terms & Conditions Apply
close-link

Join Free Giveaway!

Subscribe to our newsletter to get latest offers and giveaways!
SUBSCRIBE
close-link