Country code identification using mobile operator in iPhone programmatically?

Is there a way to get the country code from the mobile network. Can we get the name of the country of the SIM card presented on the device using the code?

Please help me with this with some working code. I checked the CoreTelephony Framework but did not get success.

+5
source share
2 answers

EDIT:. With Xcode 6, just add this line, even binding the frame to the project is done automatically:

@import CoreTelephony; 

Original: Add CoreTelephony.framework to your project. inside your class add 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); 

Please note that the country code is in the numeric code, you can find the list here

+19
source

This is inside CoreTelephony

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

All Articles