判断联网wifi
Posted 繁星Boy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断联网wifi相关的知识,希望对你有一定的参考价值。
UIApplication *app = [UIApplication sharedApplication];
NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];
NSString *state = [[NSString alloc]init];
int netType = 0;
//获取到网络返回码
for (id child in children) {
if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
//获取到状态栏
netType = [[child valueForKeyPath:@"dataNetworkType"]intValue];
switch (netType) {
case 0:
state = @"无网络";
//无网模式
break;
case 1:
state = @"2G";
break;
case 2:
state = @"3G";
break;
case 3:
state = @"4G";
break;
case 5:
{
state = @"WIFI";
}
break;
default:
break;
}
}
}
以上是关于判断联网wifi的主要内容,如果未能解决你的问题,请参考以下文章