+(
NSString
*)getNetStates{
UIApplication *application = [ UIApplication sharedApplication ];
NSArray *childrenArray = [[[application valueForKeyPath : @"statusBar" ] valueForKeyPath : @"foregroundView" ] subviews ];
// 获取到网络返回码
for ( id child in childrenArray) {
if ([child isKindOfClass : NSClassFromString ( @"UIStatusBarDataNetworkItemView" )]) {
// 获取到状态栏
netType = [[child valueForKeyPath : @"dataNetworkType" ] intValue ];
switch (netType) {
case 0 :
statenet = @" 无网络 " ;
break ;
case 1 :
statenet = @"2G" ;
break ;
case 2 :
statenet = @"3G" ;
break ;
case 3 :
statenet = @"4G" ;
break ;
case 5 :
{
statenet = @"WIFI" ;
}
break ;
default :
break ;
}
}
}
// 根据状态选择
return statenet;
}
UIApplication *application = [ UIApplication sharedApplication ];
NSArray *childrenArray = [[[application valueForKeyPath : @"statusBar" ] valueForKeyPath : @"foregroundView" ] subviews ];
NSString *statenet = [[NSString alloc]init];
int netType = 0 ;// 获取到网络返回码
for ( id child in childrenArray) {
if ([child isKindOfClass : NSClassFromString ( @"UIStatusBarDataNetworkItemView" )]) {
// 获取到状态栏
netType = [[child valueForKeyPath : @"dataNetworkType" ] intValue ];
switch (netType) {
case 0 :
statenet = @" 无网络 " ;
break ;
case 1 :
statenet = @"2G" ;
break ;
case 2 :
statenet = @"3G" ;
break ;
case 3 :
statenet = @"4G" ;
break ;
case 5 :
{
statenet = @"WIFI" ;
}
break ;
default :
break ;
}
}
}
// 根据状态选择
return statenet;
}