Created
May 21, 2011 03:59
-
-
Save marshluca/984228 to your computer and use it in GitHub Desktop.
Observer network with Reachablity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)reachabilityChanged:(NSNotification *)note | |
{ | |
Reachability* curReach = [note object]; | |
NSParameterAssert([curReach isKindOfClass: [Reachability class]]); | |
NetworkStatus status = [curReach currentReachabilityStatus]; | |
if (status == NotReachable) { | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil | |
message:@"当前没有可用网络" | |
delegate:nil | |
cancelButtonTitle:@"YES" otherButtonTitles:nil]; | |
[alert show]; | |
[alert release]; | |
} | |
} | |
- (void)observeNetwork | |
{ | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(reachabilityChanged:) | |
name: kReachabilityChangedNotification | |
object: nil]; | |
Reachability *hostReach = [[Reachability reachabilityWithHostName:@"www.google.com"] retain]; | |
[hostReach startNotifier]; | |
[hostReach release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment