iOS 获取网络类型

来源:互联网 发布:adobe mac 破解版 编辑:程序博客网 时间:2024/05/16 08:47

-(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 ;}


0 0
原创粉丝点击