Identifying the country code using mobile carrier in iPhone programmatically?

隐身守侯 提交于 2019-11-30 07:50:37
Giuseppe Mosca

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

It is inside CoreTelephony

CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!