Notification when WiFi connection available

I need a notification when device has WiFi connection is available or Device get connect via WiFi. I need to do some stuff only when WiFi is available.

I have used following code from Reachability:

BOOL status=true;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];

internetReachability = [Reachability reachabilityForInternetConnection];
[internetReachability startNotifier];

NetworkStatus internetNetworkStatus = [internetReachability currentReachabilityStatus];
status = (internetNetworkStatus == ReachableViaWiFi);

But checkNetworkStatus: method not called properly and accurately. So, please guide me to solve this problem.

Any help to solve problem must be appreciated.

Answers


I hope it will help you in your problem.

-(void) rechabilityInit
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];



self.internetConnectionReach = [Reachability reachabilityForInternetConnection];

self.internetConnectionReach.reachableBlock = ^(Reachability * reachability)
{

   NSLog(@"%@", reachability.currentReachabilityString);

    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
  dispatch_async(dispatch_get_main_queue(), ^{

      // Do stuff here when WIFI is availble

     }];
};

self.internetConnectionReach.unreachableBlock = ^(Reachability * reachability)
{
  NSLog(@"%@", reachability.currentReachabilityString);
    dispatch_async(dispatch_get_main_queue(), ^{
      [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        // do some stuff here when WIFI not present 
    }];
};    
[self.internetConnectionReach startNotifier];        

}

-(void)reachabilityChanged:(NSNotification*)note
{

     Reachability * reach = [note object];
     if (reach == self.localWiFiReach)
     {
     if([reach isReachable])
     {
     NSString * temp = [NSString stringWithFormat:@"LocalWIFI Notification Says Reachable(%@)", reach.currentReachabilityString];
     NSLog(@"%@", temp);
      }
     else
     {
     NSString * temp = [NSString stringWithFormat:@"LocalWIFI Notification Says Unreachable(%@)", reach.currentReachabilityString];
    NSLog(@"%@", temp);
     }
     }

}

Need Your Help

Embedd a flash element and make unclickable

html embed swfobject

I am trying to embed this flash banner in side but url on it is messed up.

Looking to condense my Jquery Animation Script

jquery animation overhead

I have a jquery animation script that is working properly, however, I feel like there is a way to reduce the overall overhead for the script. Here is a link to the development page:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.