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;
	}
}

Comments (6)

  1. Malini

    Very good article.More work in less code.

    Thanks

  2. 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..

  3. Does this one really need a download option?
    I have added a link to the full source code for the tutorial on “Json Login Screen”.

  4. RathaKrisna

    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 comment

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.