【问题标题】:NSLocale Country Code and Name is NullNSLocale 国家代码和名称为空
【发布时间】: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 -&gt; General -&gt; Language &amp; Region -&gt; Region Formats 并进行相应设置。它应该工作。干杯。
  • 我仔细检查了。一切都相应地设置了:(
  • 您在模拟器/设备设置 -> 区域格式中设置的区域是什么?
  • 设备和模拟器的设置。查看我的编辑。

标签: ios xcode6 nslocale


【解决方案1】:

终于找到了虫子。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多