实际上,我正在尝试从SimCard那里获得国家代码,这是我的手机。如何通过程序从Simcard获得国家代码。或者有什么吊舱能帮我弄到国家代码的细节。
提前感谢
发布于 2016-08-11 10:09:16
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.CurrentLocale的2.
NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
NSLog(@"countryCode: %@", countryCode);发布于 2016-08-11 10:07:44
您可以进口:
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>并使用以下代码:
CTCarrier* tmpCTC = [[CTCarrier alloc] init];
NSString* mcc = [tmpCTC mobileCountryCode];
NSLog([NSString stringWithFormat:@"mcc = %@",mcc]);希望它能帮到你。
发布于 2021-07-06 22:10:11
对那些需要这个的人来说。
import CoreTelephony
let networkProviders = CTTelephonyNetworkInfo().serviceSubscriberCellularProviders
let countryCode = networkProviders?.first?.value.isoCountryCodehttps://stackoverflow.com/questions/38893076
复制相似问题