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)
| 归档时间: |
|
| 查看次数: |
4509 次 |
| 最近记录: |