- (NSString *)countryNameByCode:(NSString*)countryCode
{
NSString *identifier = [NSLocale localeIdentifierFromComponents:@{NSLocaleCountryCode: countryCode}];
NSString *countryName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier];
return countryName;
}
国家名为零。为什么?
发布于 2018-05-02 16:27:28
这是仅适用于iOS 8.1 的已知问题- 不能在8.1设备上重现。请参阅下面的Xcode 6.1发行说明中的问题描述:
本地化和键盘设置(包括第三方键盘)在iOS 8.1 Simulator中未被Safari,地图和开发人员应用正确认可。[NSLocale currentLocale]返回en_US,只有英文和表情符号键盘可用。(18418630,18512161)。
有关更多详细信息,请参阅Xcode 6.1发行说明。
发布于 2018-05-02 16:43:21
请尝试下面的代码,它应该可以工作。我在我的设备和模拟器8.1上试过
- (NSString *)countryNameByCode:(NSString*)countryCode {
return [[NSLocale systemLocale] displayNameForKey:NSLocaleCountryCode value:countryCode];
}
https://stackoverflow.com/questions/-100008328
复制相似问题