如何在iOS目标C中以编程方式从simCard获取国家/地区代码 [英] How to get the country code from simCard programatically in ios objective c

查看:42
本文介绍了如何在iOS目标C中以编程方式从simCard获取国家/地区代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我正在尝试以编程方式从手机中的SimCard获取国家(地区)代码.我们如何以编程方式从Simcard获取国家/地区代码.还是有任何吊舱可以帮助我获取国家/地区代码详细信息.

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 .

预先感谢

推荐答案

1..来自 SimCard

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

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

注意:该代码在以下情况下不起作用:

Note : This code does not work in following conditions:

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

2..来自 CurrentLocale

NSLocale *currentLocale = [NSLocale currentLocale];  // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
NSLog(@"countryCode: %@", countryCode);

这篇关于如何在iOS目标C中以编程方式从simCard获取国家/地区代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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