获取当前网络类型

// 0:无网络  1:2g 2:3g 3:4g 5:wifi

+(NSInteger)getNetWorkInfo{

    UIApplication *app=[UIApplicationsharedApplication];

    

    NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];

    int type =0;

    for (id child in children) {

        if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {

            type = [[child valueForKeyPath:@"dataNetworkType"] intValue];

        }

        

    }

//    

//    NSLog(@"----%d", type);

    return type;

 

}

猜你喜欢

转载自siruoxian.iteye.com/blog/2168645