???????notification????
- (void)viewDidLoad
{
[super viewDidLoad];
DLog(@"???? www.apple.com ????????");
Reachability* reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
DLog(@"-- current status: %@"?? reach.currentReachabilityString);
// start the notifier which will cause the reachability object to retain itself!
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
[reach startNotifier];
}
- (void) reachabilityChanged: (NSNotification*)note {
Reachability * reach = [note object];
if(![reach isReachable])
{
self.notificationLabel.text = @"???粻????";
self.notificationLabel.backgroundColor = [UIColor redColor];
self.wifiOnlyLabel.backgroundColor = [UIColor redColor];
self.wwanOnlyLabel.backgroundColor = [UIColor redColor];
return;
}
self.notificationLabel.text = @"???????";
self.notificationLabel.backgroundColor = [UIColor greenColor];
if (reach.isReachableViaWiFi) {
self.wifiOnlyLabel.backgroundColor = [UIColor greenColor];
self.wifiOnlyLabel.text = @"??????wifi????";
} else {
self.wifiOnlyLabel.backgroundColor = [UIColor redColor];
self.wifiOnlyLabel.text = @"wifiδ???????????";
}
if (reach.isReachableViaWWAN) {
self.wwanOnlyLabel.backgroundColor = [UIColor greenColor];
self.wwanOnlyLabel.text = @"??????2g or 3g????";
} else {
self.wwanOnlyLabel.backgroundColor = [UIColor redColor];
self.wwanOnlyLabel.text = @"2g or 3g????δ???";
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
DLog(@"???? www.apple.com ????????");
Reachability* reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
DLog(@"-- current status: %@"?? reach.currentReachabilityString);
// start the notifier which will cause the reachability object to retain itself!
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
[reach startNotifier];
}
- (void) reachabilityChanged: (NSNotification*)note {
Reachability * reach = [note object];
if(![reach isReachable])
{
self.notificationLabel.text = @"???粻????";
self.notificationLabel.backgroundColor = [UIColor redColor];
self.wifiOnlyLabel.backgroundColor = [UIColor redColor];
self.wwanOnlyLabel.backgroundColor = [UIColor redColor];
return;
}
self.notificationLabel.text = @"???????";
self.notificationLabel.backgroundColor = [UIColor greenColor];
if (reach.isReachableViaWiFi) {
self.wifiOnlyLabel.backgroundColor = [UIColor greenColor];
self.wifiOnlyLabel.text = @"??????wifi????";
} else {
self.wifiOnlyLabel.backgroundColor = [UIColor redColor];
self.wifiOnlyLabel.text = @"wifiδ???????????";
}
if (reach.isReachableViaWWAN) {
self.wwanOnlyLabel.backgroundColor = [UIColor greenColor];
self.wwanOnlyLabel.text = @"??????2g or 3g????";
} else {
self.wwanOnlyLabel.backgroundColor = [UIColor redColor];
self.wwanOnlyLabel.text = @"2g or 3g????δ???";
}
}
????????demo???
????????wifi??

???????wifi????

????????????
???????????controller?????????Reachability(????demo???????controller???Reachability???)
????????????????Reachability????.