0

我有获取国家代码的代码。但我想要印度的国家代码,如 +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);
4

1 回答 1

3

为此,您可以使用 CoreTelephony 框架。在你的项目中包含这个框架

CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = network_Info.subscriberCellularProvider;
NSString *countryCode = carrier.mobileCountryCode
于 2013-10-11T05:43:31.560 回答