NSLocale和国家/地区名称
问题描述:
我使用此代码获取iPhone所属的国家/地区:
I used this code for getting which country iPhone belong to:
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
我希望国家名称总是用英文,但如果iPhone是用其他任何语言它以该语言返回国家名称...
and I want to get the country name always in English, but if the iPhone is in any other language it returns the country name in that language...
答
查询displayName的英语区域设置
Query an english locale for the displayName
像这样:
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString *country = [usLocale displayNameForKey: NSLocaleCountryCode value: countryCode];