-(NSString *)getNetWorkState{
UIApplication *app =[UIApplication sharedApplication];
NSArray *array =[[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
NSString *state = [[NSString alloc] init];
int netType = 0 ;
for (id child in array) {
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 4:
state = @"4G" ;
break ;
case 5:
state = @"WiFi" ;
break ;
default:
break;
}
}
}
return state ;
}
iOS 获取网络类型
最新推荐文章于 2022-11-07 23:05:29 发布