小编use*_*227的帖子

在iOS 5上获取语言环境

我有这段代码从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 …
Run Code Online (Sandbox Code Playgroud)

iphone nslocale ios5

9
推荐指数
1
解决办法
4509
查看次数

标签 统计

ios5 ×1

iphone ×1

nslocale ×1