问题描述
是否可以通过任何方式从移动网络获取国家/地区代码.是否可以通过代码获取设备中存在的SIM卡的国家/地区名称?
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?
请通过一些有效的代码帮助我.我检查了CoreTelephony Framework,但ddnt获得成功.
Please Help me out in this with some working code. I checked CoreTelephony Framework but ddnt get the success.
推荐答案
使用Xcode 6,只需添加以下行,甚至可以自动将框架链接到项目:
With Xcode 6, simply add this line, even linking the framework to the project is done automatically:
@import CoreTelephony;
原始:将CoreTelephony.framework添加到您的项目中. 在您的类中添加以下两行:
original: Add CoreTelephony.framework to your project. inside your class add this two lines:
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
这是代码:
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
这篇关于以编程方式在iPhone中使用移动运营商识别国家/地区代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!