检测运营商连接类型(3G/EDGE/GPRS)

Detect carrier connection type (3G / EDGE / GPRS)(检测运营商连接类型(3G/EDGE/GPRS))
本文介绍了检测运营商连接类型(3G/EDGE/GPRS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取运营商网络的连接类型?

How can i get the type of connection of a carrier network?

  • 我可以使用 Reachability 类获取连接是 WIFI 还是 WWAN
  • 我可以获取网络标志

  • I'm able to get if connection is WIFI or WWAN using Reachability class
  • I'm able to get network flags

可达性标志状态:WR t------ localWiFiStatusForFlags

Reachability Flag Status: WR t------ localWiFiStatusForFlags

  • 我可以使用 CaptiveNetwork

    支持的接口:(en0)

    Supported interfaces: ( en0 )

    en0 => {  
        BSSID = "xx:xx:xx:xx:xx:xx";  
        SSID = MyWifiNetwork;  
        SSIDDATA = <x1x1x1x1 x1x1x1x1 x1>;  
    }  
    

    但我无法区分 3G、EDGE 或 GPRS 连接.

    But i'm not able to differenziate 3G, EDGE or GPRS connection.

    知道也使用 iOS 私有 API 吗?

    谢谢.

    推荐答案

    从iOS 7 开始可以使用:

    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 NO;
        } 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;
    }
    

    这篇关于检测运营商连接类型(3G/EDGE/GPRS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

  • 本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

    相关文档推荐

    Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
    iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
    tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
    Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
    How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
    Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)