Checking For An Internet Connection


This code tells you if you have a network connection. You need the Reachability class from Apple.

#import "Reachability.h"

+(BOOL) doWeHaveInternetConnection{

	Reachability *hostReach = [[Reachability reachabilityWithHostName: @""] retain];
	NetworkStatus netStatus = [hostReach currentReachabilityStatus];
	BOOL isAvailable = NO;

	if (netStatus == NotReachable)
		isAvailable =  NO;

	if (netStatus == ReachableViaWiFi)
		isAvailable =  YES;


	if (netStatus == ReachableViaWWAN)
		isAvailable = YES;

	[hostReach release];
	return isAvailable;

Leave a Reply

Your email address will not be published.