Im on an application that receive data from server, the problem is when user connect to cellular data (Not 3G or WIFI), it take ages to receive data.

i had implemented this code from this Answer but im not sure if it is effective or not, sometimes it's giving me an accurate type, and sometimes it don't.

here is my code:

- (void)newtworkType {

NSArray *subviews = [[[[UIApplication sharedApplication] valueForKey:@"statusBar"] valueForKey:@"foregroundView"]subviews];
NSNumber *dataNetworkItemView = nil; for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
dataNetworkItemView = subview;
break;
}
} switch ([[dataNetworkItemView valueForKey:@"dataNetworkType"]integerValue]) {
case 0:
NSLog(@"No wifi or cellular");
break; case 1:
NSLog(@"2G");
break; case 2:
NSLog(@"3G");
break; case 3:
NSLog(@"4G");
break; case 4:
NSLog(@"LTE");
break; case 5:
NSLog(@"Wifi");
break; default:
break;
}}

Make sure that the Status bar is not hidden in your application. if it's not visible it will always return No wifi or cellular because your code reads the text in the Status bar thats all.

this is the best way to solve your problem, just make the Status bar not hidden then the application will get the text about the network type.

判断网络类型

GPRS       2G(2.5) General Packet Radia Service 114kbps
EDGE       2G(2.75G) Enhanced Data Rate for GSM Evolution 384kbps
UMTS      3G WCDMA 联通3G Universal Mobile Telecommunication System 完整的3G移动通信技术标准
CDMA     2G 电信 Code Division Multiple Access 码分多址
EVDO_0   3G (EVDO 全程 CDMA2000 1xEV-DO) Evolution - Data Only (Data Optimized) 153.6kps - 2.4mbps 属于3G
EVDO_A  3G 1.8mbps - 3.1mbps 属于3G过渡,3.5G
1xRTT      2G CDMA2000 1xRTT (RTT - 无线电传输技术) 144kbps 2G的过渡,
HSDPA    3.5G 高速下行分组接入 3.5G WCDMA High Speed Downlink Packet Access 14.4mbps
HSUPA    3.5G High Speed Uplink Packet Access 高速上行链路分组接入 1.4 - 5.8 mbps
HSPA      3G (分HSDPA,HSUPA) High Speed Packet Access
IDEN      2G Integrated Dispatch Enhanced Networks 集成数字增强型网络 (属于2G,来自维基百科)
EVDO_B 3G EV-DO Rev.B 14.7Mbps 下行 3.5G
LTE        4G Long Term Evolution FDD-LTE 和 TDD-LTE , 3G过渡,升级版 LTE Advanced 才是4G
EHRPD  3G CDMA2000向LTE 4G的中间产物 Evolved High Rate Packet Data HRPD的升级
HSPAP  3G HSPAP 比 HSDPA 快些

From iOS 7 on you can use:

CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSLog(@"Current Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
[NSNotificationCenter.defaultCenter addObserverForName:CTRadioAccessTechnologyDidChangeNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note)
{
NSLog(@"New Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
}];

I have also found this to detect a slow or fast connection:

- (BOOL)isFast:(NSString*)radioAccessTechnology {
if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
return NO;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) {
return NO;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) {
return YES;
} else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
return YES;
} return YES;
}

Objective-C determine data network type of the iOS device的更多相关文章

  1. DDN - Digital Data Network

    DDN(Digital Data Network,数字数据网)是一种利用光纤.数字微波或卫星等数字传输通道和数字交叉复用设备组成的数字数据传输网.它可以为用户提供各种速率的高质量数字专用电 数字数据网 ...

  2. Intent属性详解三 data、type和extra

    1 Data  执行时要操作的数据 在目标<data/>标签中包含了以下几种子元素,他们定义了url的匹配规则: android:scheme 匹配url中的前缀,除了“http”.“ht ...

  3. [AJAX系列]$.get(url,[data],[fn],[type])

    $.get(url,[data],[fn],[type]) 概述 通过远程HTTP GET请求载入信息 参数 url:待载入页眉的URL地址 data:待发送key/value参数 callback: ...

  4. TYPES、DATA、TYPE、LIKE、CONSTANTS、STATICS、TABLES

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT

    VMware虚拟机上网络连接(network type)的三种模式--bridged.host-only.NAT VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换 ...

  6. Intent的属性及Intent-filter配置——Data、Type属性与intent-filter配置

    Data属性通常用于向Action属性提供操作的数据,Data属性接受一个Uri对象,一个Uri对象通常通过如下形式的字符串来表示: content://com.android.contacts/co ...

  7. jQuery.post(url, [data], [callback], [type])

    jQuery.post(url, [data], [callback], [type]) 概述 通过远程 HTTP POST 请求载入信息. 这是一个简单的 POST 请求功能以取代复杂 $.ajax ...

  8. ​vmware虚拟机centos网络配置错误,执行/etc/init.d/network start 或 restart 提示Device eth0 has different MAC address than expected, ignoring

    vmware虚拟机centos网络配置错误,执行/etc/init.d/network start 或 restart 提示Device eth0 has different MAC address ...

  9. Genymotion 常见问题Unable to configure the network adapter for the virtual device解决

    Genymotion 常见问题Unable to configure the network adapter for the virtual device解决 参考:http://www.pczhis ...

随机推荐

  1. css的两种盒子模型

    css的两种盒子模型:W3C标准盒子模型.IE盒子模型 两者的相同之处:都包含margin.border.padding.content 两者的不同之处:W3C标准盒子模型的content部分不包含其 ...

  2. cd命令进入D盘

    CD命令是更改目录命令如果要进入D盘 不用这个命令 直接输入 D: 回车 即可要是你非要使用CD命令那要加参数/DCD D:系统只是认为你想在系统中记忆一下D盘所以还是返回原先目录例:D盘下有一个目录 ...

  3. easyUI dialog 弹窗 居中显示

    默认情况下应该是在屏幕居中显示的.但是有的时候没有居中只要重新纠正下就可以了 $('#add_dialog').dialog('open'); //打开添加对话框 $('#add_dialog').w ...

  4. input覆盖select实现select可写可选择

    1.有时需要一个select选择框,但是对select选择框希望是既可以选择也可以进行输入.下边的代码就是在select选择框上放了一个input框,覆盖在select上面.实现伪装的select效果 ...

  5. Python中T-SNE实现降维

    Python中T-SNE实现降维 from sklearn.manifold import TSNE from sklearn.datasets import load_iris from sklea ...

  6. svnadmin:error while loading shared libraries: libaprutil-1.so.0:cannot open shared object file: No such file or directory

    wdcp下安装svn后一直提示 svnadmin:error while loading shared libraries: libaprutil-1.so.0:cannot open shared ...

  7. Java中的深拷贝和浅拷贝

    1.浅拷贝与深拷贝概念 (1)浅拷贝(浅克隆) 浅拷贝又叫浅复制,将对象中的所有字段复制到新的对象(副本)中.其中,值类型字段(java中8中原始类型)的值被复制到副本中后,在副本中的修改不会影响到源 ...

  8. Failed to instantiate the default view controller for UIMainStoryboardFile 'Main'

    给UITableViewController 展示数据时候 删除系统自带viewController 然后拖过来一个UITableViewController 指定class后没有指定main入口 报 ...

  9. Problem A CodeForces 560A

    Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses bankn ...

  10. xlistview的XML(脚)xlistview_footer

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...