在iPhone中使用移动运营商识别国家代码以编程方式? [英] Identifying the country code using mobile carrier in iPhone Programatically?

查看:214
本文介绍了在iPhone中使用移动运营商识别国家代码以编程方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从移动网络获取国家/地区代码。我们可以通过代码获取设备中存在的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中使用移动运营商识别国家代码以编程方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆