NSLocale国家代码和名称为空

时间:2015-07-27 10:43:16

标签: 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

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).

enter image description here

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 :)