Internet connection (Rechability) not work

| | August 7, 2015

I use below code for internet connection but not work(reachabilityChanged does’t call when wifi or internet change)

//Internet.m : 
@interface Internet ()
@property (nonatomic) Reachability *Wifi;

@implementation Internet

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    self.Wifi = [Reachability reachabilityForLocalWiFi];
    [self.Wifi startNotifier];

- (void) reachabilityChanged:(NSNotification *)note
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
    if (curReach == self.Wifi)
        NetworkStatus netStatus = [curReach currentReachabilityStatus];
        if(netStatus == NotReachable)
            NSString *status=@"NO";
        else if(netStatus == ReachableViaWiFi)
            NSString *status=@"Yes";

- (void)viewDidLoad
    [super viewDidLoad];

    [self performSelectorInBackground:@selector(callInternet) withObject:nil];

    inter=[[Internet alloc]init];//inter is instance variable
    [inter checkNetwork];

One Response to “Internet connection (Rechability) not work”

  1. @sajidZare,

    in Appdelegate.h file

    //Check Internet Connection
    .//Define method for that

    in Appdelegate.m file

     //Check Internet Plugin
        #pragma mark Check Internet connection
        -(BOOL)checkInternetConnection {
            char *hostname;
            struct hostent *hostinfo;
            hostname = "";
            hostinfo = gethostbyname (hostname);
            if (hostinfo == NULL)
                NSLog(@"-> no connection!n");
                return NO;
                NSLog(@"-> connection established!n");
                return YES;

    //This is best solution, try it, may be help to you.

    Another Solution
    in your.h File

        #import "Reachability.h"            // internet Rechability
        //---rechability methods---//
        @property (nonatomic) Reachability *internetReachability;

    in your.m File

        self.internetReachability = [Reachability reachabilityForInternetConnection];
        if (self.internetReachability.currentReachabilityStatus==NotReachable)
            NSLog(@"internet is not available..");
            [self internetAlertView];
                NSLog(@"internet Available..");
    *//Here you can do whatever you want to do//*
                [self BTN_Spark:self];
            [self.internetReachability startNotifier];
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Please check the internet connection!!!" delegate:self cancelButtonTitle:@"OK"  otherButtonTitles:nil];
            [alertView show];

Leave a Reply