CTTelephonyNetworkInfo检测数据类型

时间:2015-06-16 08:23:50

标签: ios objective-c connection telephony

我已根据CTTelephony

实施了CTTelephonyNetworkInfo

我的代码

CTTelephonyNetworkInfo  *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
NSLog(@"Initial cell connection: %@", networkInfo.currentRadioAccessTechnology);

我无法获得任何回复,我的'初始单元连接'始终返回null。我在设置为wifi的模拟器上运行(我认为这是为什么显示null)。我想使用CTTelephony检测并返回连接是否为3g或4g并返回'3g'或'4g'作为字符串值

3 个答案:

答案 0 :(得分:2)

Santu C是对的。

//2G
CTRadioAccessTechnologyGPRS          
CTRadioAccessTechnologyEdge

//3G
CTRadioAccessTechnologyWCDMA         
CTRadioAccessTechnologyHSDPA   
CTRadioAccessTechnologyHSUPA     
CTRadioAccessTechnologyCDMA1x    
CTRadioAccessTechnologyCDMAEVDORev0    
CTRadioAccessTechnologyCDMAEVDORevA 
CTRadioAccessTechnologyCDMAEVDORevB
CTRadioAccessTechnologyeHRPD

//4G
CTRadioAccessTechnologyLTE

答案 1 :(得分:0)

您可以在CTTelephonyNetworkInfo上使用以下类别来获取currentRadioAccessTechnology。

#import "CTTelephonyNetworkInfo+CellularConnectionNiceName.h"

@implementation CTTelephonyNetworkInfo (CellularConnectionNiceName)


- (NSString *)cellularConnectionNiceName {

    if ([self.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
        return @"GPRS";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyEdge]) {
        return @"EDGE";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyWCDMA]) {
        return @"WCDMA";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyHSDPA]) {
        return @"HSDPA";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyHSUPA]) {
        return @"HSUPA";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
        return @"CDMA1X";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
        return @"CDMAEVDOREV0";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
        return @"CDMAEVDOREVA";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
        return @"CDMAEVDOREVB";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyeHRPD]) {
        return @"EHRPD";
    } else if ([self.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyLTE]) {
        return @"LTE";
    }
    return @"UNKNOWN";
}

注意:CTTelephonyNetworkInfo框架仅适用于Device Only。

答案 2 :(得分:-2)

  

enter image description here

Here是2G,3G,4G背后技术的链接。我相信@Reming Hsu的答案是正确的。