iOS - 检测当前网络状态 - 无网络/2G/3G/4G/WIFI

//判断网络状态  
UIApplication *app = [UIApplication sharedApplication];  
NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];  
int netType = 0;  
//获取到网络返回码  
for (id child in children) {  
    if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {  
        //获取到状态栏  
        netType = [[child valueForKeyPath:@"dataNetworkType"]intValue];  
        // 0: 无网络  1:2G 2:3G 3:4G  5:WIFI  
        NSLog(@"netType = %d", netType);  
    }  
} 

你可能感兴趣的:(iOS - 检测当前网络状态 - 无网络/2G/3G/4G/WIFI)