2012-07-10 61 views
2

是否可以確定iPhone 4s的網絡類型(GSM/CDMA)? 有沒有辦法確定iPhone 4s的網絡類型(GSM/CDMA)。我想區分GSM/WCDMA和CDMA如果可能的話。我使用下面的代碼來檢測它。是否可以在iOS5中確定iPhone 4s的網絡類型(GSM/CDMA)

size_t size; 
sysctlbyname("hw.machine", NULL, &size, NULL, 0); 
char *machine = malloc(size); 
sysctlbyname("hw.machine", machine, &size, NULL, 0); 
NSString *platform = [NSString stringWithUTF8String:machine]; 
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S"; 
if ([platform isEqualToString:@"iPhone4,3"]) return @"iPhone 4S coma"; 

可是我昏迷和WCDMA的iPhone4S測試。 它都返回iPhone4,1。我無法區分它。

+0

可能的重複http://stackoverflow.com/questions/9525305/is-it-possible-to-determine-the-network-type-gsm-cdma? – ilight 2012-07-10 15:01:13

+0

已回答http://stackoverflow.com/q/7596079/1487063 – Dustin 2012-07-10 15:20:48

回答

0

您可以使用正在用作指示器的載體。

NSString* networkType = nil; 

// Setup the Network Info and create a CTCarrier object 
// first check to ensure the developper linked the CoreTelephony framework 
Class telephonyClass = NSClassFromString(@"CTTelephonyNetworkInfo"); 
if (nil != telephonyClass) { 
    CTTelephonyNetworkInfo *networkInfo = [[[telephonyClass alloc] init] autorelease]; 

    if (nil != networkInfo) { 
     // Get mobile network code 
     NSString *mnc = [carrier mobileNetworkCode]; 
     if (mnc != nil) { 
      // set networkType based on carrier name 
      // carrier name to network type mapping left as an exercise for the reader 
      // 
     } 
    } 
} 
相關問題