- (NSString *)countryNameByCode:(NSString*)countryCode
{
NSString *identifier = [NSLocale localeIdentifierFromComponents:@{NSLocaleCountryCode: countryCode}];
NSString *countryName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier];
return countryName;
}
这返回了 nil。为什么?
最佳答案
这是一个已知的 Apple 问题,仅适用于 iOS 8.1 模拟器 - 在 8.1 设备上无法重现。请参阅 Xcode 6.1 发行说明中的以下问题描述:
Localization and Keyboard settings (including 3rd party keyboards) are not correctly honored by Safari, Maps, and developer apps in the iOS 8.1 Simulator. [NSLocale currentLocale] returns en_US and only the English and Emoji keyboards are available. (18418630, 18512161).
参见 Xcode 6.1 Release Notes了解更多详情。
关于ios - xcode 6.1 iOS 8.1 NSLocale displayNameForKey NSLocaleIdentifier 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26613011/