ios - NSLocale 国家代码和名称为空

标签 ios xcode6 nslocale

我使用以下代码作为代码和国家/地区名称,但它返回 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:0x7fbef943f810> 代码:(null) 名称(null)

语言:nl Lang2:nl

enter image description here

在设备和模拟器上都测试过。我不知道这里发生了什么。它应该可以正常工作。如果你们有任何想法请告诉我。我正在使用 xcode 6.4。

enter image description here

最佳答案

终于找到了窃听器。

我在另一个测试项目中测试了上面的代码并且工作正常但在我当前的项目中却不行。 所以我使用了开发工具 FileMerge 并比较了两者,发现下面一行有所不同。(xcshareddata->xcschemes->****.xcscheme)。

enter image description here

我不知道 language = "nl"是如何到达那里的,可能是由于错误的合并,但回滚和重新合并也没有用。

手动删除线解决了我的幽灵问题:)

关于ios - NSLocale 国家代码和名称为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31651015/

相关文章:

ios - Swift - 如何根据属性重新排序tableview中的所有单元格?

ios - 无法创建 Podfile,因为 'plist file at path doesn' 不存在”

xcode6 - Xcode 通常可能生成的所有有效 SystemCapability 键有哪些?

ios - 无法将 GMT 字符串日期转换为 Nsdate

iOS NSDateFormatter 即使是 UTC 也需要 NSLocale

iOS VoiceOver – 在标准 UIView 中实现 “x of y” 读出?

ios - 转换 [字符串 : AnyObject] to [String: Any]

error-handling - 如何修复 "fatal error: can' t 索引空缓冲区”

iPhone 使用用户区域设置但以其他语言显示日期

ios - UIInterfaceOrientation 信息.plist