| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
bx52
9年前发布

iOS获取网络的最新方法

typedef enum {     NETWORK_TYPE_NONE= 0,     NETWORK_TYPE_WIFI= 1,     NETWORK_TYPE_3G= 2,     NETWORK_TYPE_2G= 3,    }NETWORK_TYPE;      然后通过获取手机信号栏上面的网络类型的标志    + (int)dataNetworkTypeFromStatusBar {         UIApplication *app = [UIApplicationsharedApplication];     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;         }     }      int netType = NETWORK_TYPE_NONE;  NSNumber * num = [dataNetworkItemView valueForKey:@"dataNetworkType"];  if (num == nil) {             netType = NETWORK_TYPE_NONE;         }else{      int n = [num intValue];  if (n == 0) {             netType = NETWORK_TYPE_NONE;         }elseif (n == 1){             netType = NETWORK_TYPE_2G;         }elseif (n == 2){             netType = NETWORK_TYPE_3G;         }else{             netType = NETWORK_TYPE_WIFI;         }         }      return netType;  }