在iOS 5上获取语言环境

use*_*227 9 iphone nslocale ios5

我有这段代码从NSLocale获取一些信息(当前国家,国家名称).

它在iOS 4.3中没有任何问题,但在iOS 5中崩溃.

在检查似乎[现场localeIdentifier]和[区域displayNameForKey:值:]没有在所有的工作,但同时建立它没有检测到任何警告和错误.

我能做些什么才能让它在iOS 5中运行?

// Create a pool for autoreleased objects

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // Get the current country and locale information of the user
    NSLocale *locale = [NSLocale currentLocale];
    NSString *currentLocaleID = [locale localeIdentifier];    //returns en_US instead of the actual country stored in phone settings
    NSDictionary *localeDictionary = [NSLocale componentsFromLocaleIdentifier:currentLocaleID];     
    NSString *currentCountry = [locale displayNameForKey:NSLocaleCountryCode 
                                                   value:[localeDictionary objectForKey:NSLocaleCountryCode]];     // returns nil

    // Get the list of country codes
    NSArray *countryCodeArray = [NSLocale ISOCountryCodes];
    NSMutableArray *sortedCountryNameArray = [NSMutableArray array];


    for (NSString *countryCode in countryCodeArray) {
        NSString *displayNameString = [locale displayNameForKey:NSLocaleCountryCode value:countryCode];   //displayNameString is nil after executing this line
        [sortedCountryNameArray addObject:displayNameString];   //app crashes here
    }

    // Drain the autoreleased pool
    [pool drain];
Run Code Online (Sandbox Code Playgroud)

lem*_*nar 2

这在 iOS 5.1 或 5.1.1 中不会崩溃