iOS?????Reachability ???????
???????????? ???????[ 2014/12/1 11:25:51 ] ?????????????? iOS ????
???????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????.
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11