Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying the country code using mobile carrier in iPhone programmatically?

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.

like image 530
i_Intiution Avatar asked Nov 27 '12 13:11

i_Intiution


1 Answers

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

like image 166
Giuseppe Mosca Avatar answered Sep 19 '22 17:09

Giuseppe Mosca