如何在ios objective c中以编程方式从simCard获取国家代码
实际上,我正试图通过编程从手机中的SimCard获取国家代码。如何通过编程从Simcard获取国家代码。或者是否有任何pod可以帮助我获得国家代码的详细信息 提前感谢您可以导入:如何在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
#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);