iphone - NSLocale 和国家名称

我使用此代码获取 iPhone 属于哪个国家/地区:

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];

并且我希望始终使用英语获取国家/地区名称,但如果 iPhone 使用任何其他语言,它会返回该语言的国家/地区名称...

最佳答案

查询显示名称的英语语言环境

像这样:

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

NSString *country = [usLocale displayNameForKey: NSLocaleCountryCode value: countryCode];

https://stackoverflow.com/questions/6177309/

相关文章:

objective-c - 'pod install' 不会更新现有的 pod

iphone - 将 HEX NSString 转换为 NSData

iphone - iOS 7 表格 View 无法自动调整内容插入

c - Objective C boolean 数组

iphone - 将长格式的 NSString 拆分为多行

ios - 将 NSInteger 转换为 NSIndexpath

ios - 为什么我的 UIButton 的 "touch up inside"事件没有被调用?

objective-c - UIAlertController 延迟显示

objective-c - 通过指针运算与 C 中的下标访问数组值

objective-c - 恢复 iOS7 之前的 UINavigationController p