//// 网络类型
typedef enum {
NETWORK_TYPE_NONE= 0,
NETWORK_TYPE_2G= 1,
NETWORK_TYPE_3G= 2,
NETWORK_TYPE_4G= 3,
NETWORK_TYPE_5G= 4,// 5G目前为猜测结果
NETWORK_TYPE_WIFI= 5,
}NETWORK_TYPE;
+(NETWORK_TYPE)getNetworkTypeFromStatusBar {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSNumber *dataNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
dataNetworkItemView = subview;
break;
}
}
NETWORK_TYPE nettype = NETWORK_TYPE_NONE;
NSNumber * num = [dataNetworkItemView valueForKey:@"dataNetworkType"];
nettype = [num intValue];
return nettype;
}
网友评论