我有获取国家/地区代码的代码。但我希望印度的国家代码如+91。怎么弄?
NSArray *countryCodes = [NSLocale ISOCountryCodes];
NSMutableArray *countries = [NSMutableArray arrayWithCapacity:[countryCodes count]];
for (NSString *countryCode in [NSLocale ISOCountryCodes]) {
NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];
NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier];
[countries addObject: country];
}
NSDictionary *codeForCountryDictionary = [[NSDictionary alloc] initWithObjects:countryCodes forKeys:countries];
NSLog(@”%@”,codeForCountryDictionary);
答案 0 :(得分:3)
您可以将CoreTelephony框架用于此目的。在您的项目中包含此框架
CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = network_Info.subscriberCellularProvider;
NSString *countryCode = carrier.mobileCountryCode