Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ios objective c中以编程方式从simCard获取国家代码_Ios_Objective C - Fatal编程技术网

如何在ios objective c中以编程方式从simCard获取国家代码

如何在ios objective c中以编程方式从simCard获取国家代码,ios,objective-c,Ios,Objective C,实际上,我正试图通过编程从手机中的SimCard获取国家代码。如何通过编程从Simcard获取国家代码。或者是否有任何pod可以帮助我获得国家代码的详细信息 提前感谢您可以导入: #import <CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> 希望它能帮助您。1。来自SimCard #import <CoreTelephony/CTTelephonyNetwo

实际上,我正试图通过编程从手机中的SimCard获取国家代码。如何通过编程从Simcard获取国家代码。或者是否有任何pod可以帮助我获得国家代码的详细信息

提前感谢

您可以导入:

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

希望它能帮助您。

1。来自SimCard

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

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

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

尝试这些链接,如果你只是创建一个CTCarrier对象,它将不会有任何信息填写。您必须使用:CTCarrier*carrier=[[CTTelephonyNetworkInfo new]subscriberCellularProvider];就像另一个答案一样。请编辑或删除此答案。
1.Airplane mode.
2.No SIM card in the device.
3.Device is outside the cellular service range.
NSLocale *currentLocale = [NSLocale currentLocale];  // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
NSLog(@"countryCode: %@", countryCode);