IOS的网络提示(E\2G\3G\4G\WIFI\无网)
来源:互联网 发布:xalharnet软件下载 编辑:程序博客网 时间:2024/04/29 13:47
Reachability(官方)的获取方法是打开Xcode,同事按住 " command + shift + / " 就可以调出这个界面,如下:
点击 Documentation and API Reference 后会出现下面图:
在红色(红色是我标记的,其实是没有的)的框内输入 Reachability ,然后会弹出下图:
点击红色框内的 Reachability ,然后弹出下面的图:
在点击 Open Project ,打开并下载该工程。
3、官方 Reachability 的不足
看官方给出的监控返回类型如下:
从上图我们可以看到官方,支持的情况。不足在于手机网络模式整合,不能区分2G\3G\4G、E等网络。
4、我们对官方的 Reachability 进行扩展,让其支持 2~4G和E 网络。
1》修改官方返回的网络枚举,如下图:
2》添加 #import<CoreTelephony/CTTelephonyNetworkInfo.h> 库,如下图:
3》核心代码更改区,如下图:
- #pragma mark - Network Flag Handling
- - (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags
- {
- PrintReachabilityFlags(flags, "networkStatusForFlags");
- if ((flags & kSCNetworkReachabilityFlagsReachable) == 0)
- {
- // The target host is not reachable.
- return NotReachable;
- }
- NetworkStatus returnValue = NotReachable;
- if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)
- {
- /*
- If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi...
- */
- returnValue = ReachableViaWiFi;
- }
- if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) ||
- (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0))
- {
- /*
- ... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs...
- */
- if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0)
- {
- /*
- ... and no [user] intervention is needed...
- */
- returnValue = ReachableViaWiFi;
- }
- }
- if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN)
- {
- /*
- ... but WWAN connections are OK if the calling application is using the CFNetwork APIs.
- */
- /*! 版本兼容
- */
- float systemVersion = [UIDevice currentDevice].systemVersion.floatValue;
- if (systemVersion>=7.0) {
- CTTelephonyNetworkInfo * telephonyNetwork = [CTTelephonyNetworkInfo new];
- /*! 获取当前网络的名字
- */
- NSString * NetworkNameString = [telephonyNetwork currentRadioAccessTechnology];
- if (NetworkNameString) {
- /*! 网络区分
- CTRadioAccessTechnologyGPRS - 2G
- CTRadioAccessTechnologyEdge - 2G (sometimes called 2.5G)
- CTRadioAccessTechnologyWCDMA - 3G
- CTRadioAccessTechnologyHSDPA - 3G (sometimes called 3.5G)
- CTRadioAccessTechnologyHSUPA - 3G
- CTRadioAccessTechnologyCDMA1x - 2G
- CTRadioAccessTechnologyCDMAEVDORev0 - 3G
- CTRadioAccessTechnologyCDMAEVDORevA - 3G
- CTRadioAccessTechnologyCDMAEVDORevB - 3G
- CTRadioAccessTechnologyeHRPD - 3G (or 3.5 - eHRPD is to allow migration from CDMA EVDO to LTE)
- CTRadioAccessTechnologyLTE - 4G (allowed to be called 4G by the ITU as mentioend above)
- */
- if ([NetworkNameString isEqualToString:CTRadioAccessTechnologyGPRS]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyEdge]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
- returnValue = ReachableVia2G;
- }else if ([NetworkNameString isEqualToString:CTRadioAccessTechnologyWCDMA]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyHSDPA]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyHSUPA]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyHSUPA]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]||[NetworkNameString isEqualToString:CTRadioAccessTechnologyeHRPD]){
- returnValue = ReachableVia3G;
- }else if ([NetworkNameString isEqualToString:CTRadioAccessTechnologyLTE]){
- returnValue = ReachableVia4G;
- }else{
- returnValue = ReachableViaWWAN;
- }
- }else{
- returnValue = ReachableViaWWAN;
- }
- }else{
- /*! 低版本
- */
- returnValue = ReachableViaWWAN;
- }
- }
- return returnValue;
- }
5、对无网络的设置处理,做兼容,如下图:
6、完整的Demo下载地址
链接: https://pan.baidu.com/s/1hsysOPe 密码: jz3q
7、效果图
http://bbs.open.qq.com/thread-41299806-1-1.html
http://club.suning.com/thread-2332951-1-1.html
http://club.suning.com/thread-2332952-1-1.html
http://club.suning.com/thread-2332950-1-1.html
http://bbs.open.qq.com/thread-41311291-1-1.html
http://bbs.open.qq.com/thread-41317646-1-1.html
http://bbs.open.qq.com/thread-41317523-1-1.html
http://bbs.open.qq.com/thread-41317410-1-1.html
http://bbs.open.qq.com/thread-41317312-1-1.html
http://bbs.open.qq.com/thread-41317117-1-1.html
http://bbs.open.qq.com/thread-41316953-1-1.html
http://bbs.open.qq.com/thread-41316781-1-1.html
http://bbs.open.qq.com/thread-41316558-1-1.html
http://bbs.open.qq.com/thread-41316180-1-1.html
http://bbs.open.qq.com/thread-41315764-1-1.html
http://bbs.open.qq.com/thread-41315504-1-1.html
http://bbs.open.qq.com/thread-41314843-1-1.html
http://bbs.open.qq.com/thread-41314185-1-1.html
http://bbs.open.qq.com/thread-41313632-1-1.html
http://bbs.open.qq.com/thread-41313516-1-1.html
http://bbs.open.qq.com/thread-41313394-1-1.html
http://bbs.open.qq.com/thread-41313245-1-1.html
http://bbs.open.qq.com/thread-41313092-1-1.html
http://bbs.open.qq.com/thread-41312914-1-1.html
http://bbs.open.qq.com/thread-41312207-1-1.html
http://bbs.open.qq.com/thread-41311291-1-1.html
http://bbs.open.qq.com/thread-41309693-1-1.html
http://bbs.open.qq.com/thread-41307900-1-1.html
http://bbs.open.qq.com/thread-41307765-1-1.html
http://bbs.open.qq.com/thread-41307680-1-1.html
http://bbs.open.qq.com/thread-41307585-1-1.html
http://bbs.open.qq.com/thread-41307525-1-1.html
http://bbs.open.qq.com/thread-41305683-1-1.html
http://bbs.open.qq.com/thread-41305565-1-1.html
http://bbs.open.qq.com/thread-41305508-1-1.html
http://bbs.open.qq.com/thread-41305375-1-1.html
http://bbs.open.qq.com/thread-41305282-1-1.html
http://bbs.open.qq.com/thread-41305169-1-1.html
http://bbs.open.qq.com/thread-41304911-1-1.html
http://bbs.open.qq.com/thread-41304753-1-1.html
http://bbs.open.qq.com/thread-41304599-1-1.html
http://bbs.open.qq.com/thread-41303486-1-1.html
http://bbs.open.qq.com/thread-41303382-1-1.html
http://bbs.open.qq.com/thread-41303290-1-1.html
http://bbs.open.qq.com/thread-41303220-1-1.html
http://bbs.open.qq.com/thread-41303144-1-1.html
http://bbs.open.qq.com/thread-41303056-1-1.html
http://bbs.open.qq.com/thread-41302940-1-1.html
http://bbs.open.qq.com/thread-41302836-1-1.html
http://bbs.open.qq.com/thread-41302710-1-1.html
http://bbs.open.qq.com/thread-41302506-1-1.html
http://bbs.open.qq.com/thread-41302272-1-1.html
http://bbs.open.qq.com/thread-41302124-1-1.html
http://lvyou.baidu.com/plan/07bb04ccb6d8b30d14cfef28
http://lvyou.baidu.com/plan/9d89efe97a230738bf238538
http://lvyou.baidu.com/plan/31bc416aa4dafa28ad216106
http://lvyou.baidu.com/plan/2abcd09c11d463b4a9d11ff9
http://lvyou.baidu.com/plan/ae15770ba2ae44da9e172eee
http://lvyou.baidu.com/plan/adb1250382f97ce8ceddfbf5
http://lvyou.baidu.com/plan/8f016f1d093fb20082f9f9bc
http://lvyou.baidu.com/plan/b63f2820536896e6f1bf886c
http://lvyou.baidu.com/plan/8a35861fd374140f90f0eb7f
http://lvyou.baidu.com/plan/e7aa30404a3ab91b77ef525b
- IOS的网络提示(E\2G\3G\4G\WIFI\无网)
- IOS的网络提示(E\2G\3G\4G\WIFI\无网)
- ios网络开发区分2G/3G/4G/WIFI/无网络
- iOS - 检测当前网络状态 - 无网络/2G/3G/4G/WIFI
- iOS开发测试不同的网络环境2G/3G/4G/WiFi
- 状态栏通知网络链接的情况(wifi 2g/3g/4g/无网络链接状态)
- IOS判断运营商网络类型2G/3G/4G/WIFI/是否有网络
- iOS获取设备网络状态,2G,3G,4G,wifi,非Reachability
- iOS开发 - 检测网络状态(WIFI、2G/3G/4G)
- iOS-检测监听网络状态(WIFI、2G/3G/4G)
- iOS获取当前网络类型(Wifi、2G、3G、4G)
- iOS获取网络状态,区分2G、3G、4G、WIFI,非reachability
- iOS开发-Reachability实时检测Wifi,2G/3G/4G/网络状态
- 判断IOS当前网络类型是2G/3G/4G/WIFI
- iOS平台判断2G,3G,wifi网络类型
- iOS app网络监测,WiFi,4g,无网络,其他
- 安卓获取手机的网络状态(wifi,2g,3g,4g)
- android 处理网络状态——无网,2g,3g,wifi,ethernet,other
- BuildR Procedural Building Generator使用教程-建筑建模
- 我眼中的设计模式(7)
- 欢迎使用CSDN-markdown编辑器
- 图论之初,拓扑排序、前向星(通过存储边来存储图)加优先队列对拓扑的优化-----hdu1285
- MFC:拖动无标题窗口的三种方法
- IOS的网络提示(E\2G\3G\4G\WIFI\无网)
- 带新手走进神秘的HTTP协议
- Hibernate表映射关系
- 第一篇博文 2.20工作总结
- VMWare上配置Linux虚拟机的网卡
- 。
- win7安装pygraphviz
- Android Studio中apk签名打包 以及获取 应用签名字符串
- Canal配置