Skip to content

Instantly share code, notes, and snippets.

@raveman
Created August 13, 2012 05:38
Show Gist options
  • Select an option

  • Save raveman/3337210 to your computer and use it in GitHub Desktop.

Select an option

Save raveman/3337210 to your computer and use it in GitHub Desktop.
Reachability test
#import "Reachability.h"
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"];
[reach startNotifier];
}
- (void)viewDidUnload
{
[super viewDidUnload];
[reach stopNotifier];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)reachabilityChanged:(NSNotification*)note
{
Reachability * reach = [note object];
if([reach isReachable]){
NSLog(@"Notification Says Reachable");
}
else {
NSLog(@"Notification Says UnReachable");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment