我使用此代码来获取iPhone所属的国家/地区:

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];

我想始终以英语获取国家名称,但是如果iPhone使用其他任何语言,它将以该语言返回国家名称...

最佳答案

在英语语言环境中查询displayName

像这样:

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

NSString *country = [usLocale displayNameForKey: NSLocaleCountryCode value: countryCode];

关于iphone - NSLocale和国家/地区名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6177309/

10-09 06:40
查看更多