2013-10-11 65 views
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); 

回答

3

您可以使用CoreTelephony框架来达到此目的。将此框架包含在您的项目中

CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new]; 
CTCarrier *carrier = network_Info.subscriberCellularProvider; 
NSString *countryCode = carrier.mobileCountryCode 
相关问题