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

ios - NSLocale国家代码和名称为空,第1张

我在代码和国家/地区名称中使用以下代码,但它返回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

ios - NSLocale国家代码和名称为空,enter image description here,第2张

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

ios - NSLocale国家代码和名称为空,enter image description here,第3张

最佳答案:

1 个答案:

答案 0 :(得分:3)

Finally found the bugger.

I tested the above code in another test project and was working fine but not in my current project. So i used the developer tool FileMerge and compared the two and found a difference in the below line.(xcshareddata->xcschemes->****.xcscheme).

ios - NSLocale国家代码和名称为空,enter image description here,第4张

I don't know how the language = "nl" got there may be due to a bad merge but rolling back and re-merge didn't work either.

Manually removing the line solved my Ghostly Problem :)

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复