【发布时间】:2015-07-27 10:43:16
【问题描述】:
我使用下面的代码作为代码和国家名称,但它返回 null。
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
NSLog(@"Language : %@ Lang2 : %@",[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0],[[NSLocale preferredLanguages] objectAtIndex:0]);
NSLog(@"Locale:%@ Code:%@ Name%@:", locale, countryCode, country);
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
fr,
de,
nl,
ja,
es,
tr,
it,
pl,
pt,
);
日志:区域设置:<__nscflocale:> 代码:(null)名称(null)
语言:nl Lang2:nl
在设备和模拟器上都进行了测试。我不知道这里发生了什么。它应该可以正常工作。如果你们有任何想法,请告诉我。我使用的是 xcode 6.4。
【问题讨论】:
-
它在使用 XCode 6.4 时适用于我,我认为您需要检查您的
Settings -> General -> Language & Region -> Region Formats并进行相应设置。它应该工作。干杯。 -
我仔细检查了。一切都相应地设置了:(
-
您在模拟器/设备设置 -> 区域格式中设置的区域是什么?
-
设备和模拟器的设置。查看我的编辑。