To do this, you need to configure the notification handler:
Reachability *reach = [Reachability reachabilityWithHostName:@"http://google.com"]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; [reach startNotifier];
Then we implement the handler as follows:
- (void) reachabilityChanged:(Reachability *) reach { if ([reach isReachable]) { NSLog(@"connection"); } else{ NSLog(@"no connection"); } }
Also, when you donβt need to know when something is changing, remove yourself as an observer:
[[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
source share