iOS - 检测当前网络状态 - 无网络/2G/3G/4G/WI
作者:
别人家的程序员 | 来源:发表于
2017-06-29 10:22 被阅读21次//判断网络状态
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/WI
本文链接:https://www.haomeiwen.com/subject/syhmcxtx.html
网友评论