Constantly listen to the availability of the Internet?

I understand how I can check the availability of the Internet in my application, but I need to constantly monitor the achievement, wide coverage of the application. Therefore, if any point in the application changes the connection status, I can respond.

How could I achieve something like this?

+4
source share
1 answer

You need to add an observer to notify about availability changes:

First import into your class: #import "Reachability.h"

then add an observer:

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


-(BOOL)reachabilityChanged:(NSNotification*)note
{
    BOOL status =YES;
    NSLog(@"reachabilityChanged");

    Reachability * reach = [note object];

    if([reach isReachable])
    {
        //notificationLabel.text = @"Notification Says Reachable"
        status = YES;
        NSLog(@"NetWork is Available");
    }
    else
    {
        status = NO;
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"You are not connected to the internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    return status;
}
+4
source

All Articles