2011-07-05 3 views
9

NSLocale에서 몇 가지 정보 (현재 국가, 국가 이름)를 얻는 코드 조각이 있습니다. [: 값 : 로케일 displayNameForKey] 전혀 작동하지 않습니다하지만 경고 및 오류는 없었다 그것을 확인하면 아이폰 OS (5)iOS 5에서 로케일 얻기

에서

그것은 아이폰 OS 4.3에서 문제없이 작동하지만 충돌 [로케일 localeIdentifier]와이 보인다 그것을 구축하는 동안 발견.

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]; 
+2

우리 때문에 NDA의 아직 여기에 iOS5를 질문에 대답 할 수 없다. Apple 개발자 포럼에 질문하거나 Apple과 함께 RADAR 티켓을 버그로여십시오. –

답변

2

이 아이폰 OS 5.1에서 충돌하지 않거나 5.1.1