实际上,我正在尝试从我手机中的 SimCard 中以编程方式获取国家/地区代码。我们如何以编程方式从 Simcard 获取国家代码。或者是否有任何 pod 可以帮助我获取国家代码详细信息。
提前致谢
最佳答案
1. 来自 SimCard
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
CTCarrier *carrier = [[CTTelephonyNetworkInfo new] subscriberCellularProvider];
NSString *countryCode = carrier.isoCountryCode;
NSLog(@"countryCode: %@", countryCode);
注意:此代码在以下情况下不起作用:
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 - 如何在 ios objective c 中以编程方式从 sim 卡获取国家代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38893076/