Chintu the cool kid Chintu the cool kid - 1 year ago 106
iOS Question

How to get the country code from simCard programatically in ios objective c

Actually I am trying to get the country code programatically from SimCard which is in my phone . How can we get the country code from Simcard programatically . or is there any pod that could help me get the country code details .

Thanks in advance

Answer Source

1. From SimCard

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

CTCarrier *carrier = [[CTTelephonyNetworkInfo new] subscriberCellularProvider];
NSString *countryCode = carrier.isoCountryCode;
NSLog(@"countryCode: %@", countryCode);

note this is not work if

1.Airplane mode.
2.No SIM card in the device.
3.Device is outside of cellular service range.

2. From CurrentLocale

NSLocale *currentLocale = [NSLocale currentLocale];  // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
NSLog(@"countryCode: %@", countryCode);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download