获取网络状态
-(void)networkDetailStatus{
UIApplication* app = [UIApplicationsharedApplication];
UIView*statusV = [appvalueForKeyPath:@"statusBar"];
//状态栏背景view
UIView* statusBarBackgroundView = statusV.subviews[0];
//状心栏前景view
UIView* statusBarForegroundView = statusV.subviews[1];
//状态栏背景view是没有颜色的,只有设置颜色后才会有颜色
UIView* SignalStrengthItemView =nil;//信号强度与信号格数
UIView* ServiceItemView =nil;//电信运营商名字
UIView* DataNetworkItemView =nil;//当前网络类型_percentString
UIView* BatteryItemView =nil;//电池状态
UIView* BatteryPercentItemView =nil;//电池百分比
UIView* IndicatorItemView =nil;//锁屏指示器
UIView* TimeItemView =nil;//当前的时间不包括秒数
for(UIView* viewinstatusBarForegroundView.subviews) {
if([viewisKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView")class]]) {
SignalStrengthItemView = view;
}elseif([viewisKindOfClass:[NSClassFromString(@"UIStatusBarServiceItemView")class]]){
ServiceItemView = view;
}elseif([viewisKindOfClass: [NSClassFromString(@"UIStatusBarDataNetworkItemView")class]]){
DataNetworkItemView = view;
}elseif([viewisKindOfClass: [NSClassFromString(@"UIStatusBarBatteryItemView")class]]){
BatteryItemView = view;
}elseif([viewisKindOfClass: [NSClassFromString(@"UIStatusBarBatteryPercentItemView")class]]){
BatteryPercentItemView = view;
}elseif([viewisKindOfClass: [NSClassFromString(@"UIStatusBarIndicatorItemView")class]]){
IndicatorItemView = view;
}elseif([viewisKindOfClass: [NSClassFromString(@"UIStatusBarTimeItemView")class]]){
TimeItemView = view;
}
}
intnetworkType = [[DataNetworkItemViewvalueForKey:@"_dataNetworkType"]intValue];
switch(networkType) {
case0:
{
NSLog(@"没有网络");
}
break;
case1:
{
}
break;
case2:
{
NSLog(@"3G");
}
break;
case3:
{
NSLog(@"4G");
}
break;
case4:
{
}
break;
case5:
{
NSLog(@"wifi");
}
break;
default:
break;
}
}