0

I use reacheability class for checking my network connectivity in my app...

Reachability *reach = [Reachability reachabilityForInternetConnection]; 
    NetworkStatus netStatus = [reach currentReachabilityStatus];    
    if (netStatus==NotReachable)
    {
        NSLog(@"NR");
    }

I need to find when the network status change (i.e when the network status changes from reachable to notreachable and vice versa).

Is there any delegates to find this thinks, Any suggestions ?

Vikas S Singh
  • 1,748
  • 1
  • 14
  • 29
Icoder
  • 330
  • 3
  • 25

3 Answers3

1

I suggest to make use of Apple's Reachability class. Here is a sample App by Apple.

and also check this links.

http://www.switchonthecode.com/tutorials/iphone-snippet-detecting-network-status

Vikas S Singh
  • 1,748
  • 1
  • 14
  • 29
  • Well thanks for ur answer..... But hw my app can trace the changes in network status?? – Icoder Sep 08 '12 at 06:24
  • add the timer in applications delegate and call the network connections method. like this http://stackoverflow.com/questions/4538168/how-to-check-internet-status-in-iphone – Vikas S Singh Sep 08 '12 at 06:26
  • 1
    Use NSNotificationCenter and try to call network connections method in your view controller view – Vikas S Singh Sep 08 '12 at 06:37
  • Also checked this link http://stackoverflow.com/questions/339089/can-the-iphone-sdk-obtain-the-wi-fi-ssid-currently-connected-to http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library may be helped you – Vikas S Singh Sep 08 '12 at 06:46
0

Used this flag kReachabilityChangedNotification to find the change in network status and passed that to a NSNotificationCenter

Here is the code:

NSString *host = @"https://www.apple.com"; // Put your host here

        // Set up host reach property
       hostReach = [Reachability reachabilityWithHostname:host];

                          // Enable the status notifications
                          [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
                           [hostReach startNotifier];

   - (void) reachabilityChanged: (NSNotification* )note
{
    Reachability *reachability = [note object];
    NSParameterAssert([reachability isKindOfClass:[Reachability class]]);
    if (reachability == hostReach) {
        Reachability *reach = [Reachability reachabilityForInternetConnection]; 
        NetworkStatus netStatus = [reach currentReachabilityStatus];    
        if (netStatus==NotReachable)
        {
            NSLog(@"notreacheable");
        }
        else {
            NSLog(@"reacheable");
            [[NSNotificationCenter defaultCenter]postNotificationName:@"startUpdatingTable" object:nil];
        }
    }
}
Icoder
  • 330
  • 3
  • 25
-1

use Reachability" class

add flooding method in app delegate so you can use this method any ware in project

#import "Reachability.h"
-(BOOL)isHostAvailable
{
    //return NO; // force for offline testing
    Reachability *hostReach = [Reachability reachabilityForInternetConnection];
    NetworkStatus netStatus = [hostReach currentReachabilityStatus];
    return !(netStatus == NotReachable);
}
freelancer
  • 1,658
  • 1
  • 16
  • 37