9
我有這段代碼從NSLocale獲取一些信息(當前國家,國家名稱)。在iOS 5上獲取語言環境
這工作沒有任何問題的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];
我們不能在這裏回答問題的iOS5還因爲NDA的。在蘋果開發者論壇中提問並且/或者將蘋果公司的RADAR票證作爲bug發佈。 –