5

Is there any way to get the country code from mobile network. Can we get the country name of the SIM present in the Device through code?

Please Help me out in this with some working code. I checked CoreTelephony Framework but ddnt get the success.

Cœur
  • 37,241
  • 25
  • 195
  • 267
i_Intiution
  • 228
  • 4
  • 16

2 Answers2

19

EDIT: With Xcode 6, simply add this line, even linking the framework to the project is done automatically:

@import CoreTelephony;

original: Add CoreTelephony.framework to your project. inside your class add this two lines:

#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

this is the code:

CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];


// Get carrier name
NSString *carrierName = [carrier carrierName];
if (carrierName != nil)
    NSLog(@"Carrier: %@", carrierName);

// Get mobile country code
NSString *mcc = [carrier mobileCountryCode];
if (mcc != nil)
    NSLog(@"Mobile Country Code (MCC): %@", mcc);

// Get mobile network code
NSString *mnc = [carrier mobileNetworkCode];

if (mnc != nil)
    NSLog(@"Mobile Network Code (MNC): %@", mnc);

Note that country code is in numeric code you can find the list here

Aviel Gross
  • 9,770
  • 3
  • 52
  • 62
Giuseppe Mosca
  • 1,323
  • 12
  • 18
  • I've seen comments on other questions that suggest that the information returned is that of the carrier the phone is locked to, and not the carrier in use when roaming. For example: http://stackoverflow.com/questions/853467/retreiving-carrier-name-from-iphone-programmatically Hmm .. further reading suggests that the mnc does change when roaming. – Peter M Nov 27 '12 at 13:25
1

It is inside CoreTelephony

CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
piggyback
  • 9,034
  • 13
  • 51
  • 80