Skip to content
Blog iOS: Check whether internet connection is available

iOS: Check whether internet connection is available

Here, i am just checking whether network connectivity is available to a server and its done synchronously.
You can use Reachability if you need notifications when there is any change in the network connectivity.

For this you have to include the SystemConfiguration.framework in your project.

Now add,

#import "SystemConfiguration/SystemConfiguration.h"

and the below function to your .m file.

- (BOOL) isConnectionAvailable
{
	SCNetworkReachabilityFlags flags;
        BOOL receivedFlags;
        
        SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"dipinkrishna.com" UTF8String]);
        receivedFlags = SCNetworkReachabilityGetFlags(reachability, &flags);
        CFRelease(reachability);
        
        if (!receivedFlags || (flags == 0) )
        {
        	return FALSE;
        } else {
		return TRUE;
	}
}

6 thoughts on “iOS: Check whether internet connection is available”

  1. Great tutorials, great examples with complete explanations.
    Dipin bhai please make some tutorial on color picker also, like if I have my own picture in an imageview and I want to get the color and its values, e.g: like if i click on head it returns me black color with its values rgb hsv and hex code..

  2. Can you add Source code Download options please.. many of your article is really helped me lot. if it is having download option means, it will be more helpful for us.. thank you for such a great work.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.