determine ios connectivity states wifi 3g

Method 1

Many people use an easy and dirty way:

([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"]]!=NULL)?YES:NO;

Mehthod 2 (better):

Follow following 3 easy steps –

Step 1: Include “SystemConfiguration.framework” framework in your project

Step 2: Included Apple’s Reachability.h and Reachability.m from Reachability example

Step 3: Now add this code anywhere in your .m.

Reachability* wifiReach = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];

switch (netStatus)
{
    case NotReachable:
    {
        NSLog(@"Access Not Available");
        break;
    }

    case ReachableViaWWAN:
    {
        NSLog(@"Reachable WWAN");
        break;
    }
    case ReachableViaWiFi:
    {
        NSLog(@"Reachable WiFi");
        break;
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s