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

来源:互联网 发布:淘宝天猫入驻费用 编辑:程序博客网 时间:2024/04/28 03:48

//判断网络状态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);    }}



0 0