Monday, 17 June 2013

To check internet availability xcode

Firstly add
SystemConfiguration/SystemConfiguration framework in your project and include in your class.
and also add Reachability.h and Reachability.m (apple developer help class) from  this link
in your project. 
and include in your class.m file.

#import <SystemConfiguration/SystemConfiguration.h>
#import "Reachability.h"

Add below method in your class.m file

- (BOOL)connected
    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [reachability currentReachabilityStatus];
    return !(networkStatus == NotReachable);

- (void)viewDidLoad
[super viewDidLoad];

  if (![self connected]) 
        // not connected
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet Connection Not Found" message:@"Please check your network settings!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
    } else
        // connected, do some internet stuff