使用 NSLocaleCountryCode 的国家/地区列表
我希望能够根据用户位置更改应用程序。我使用下面的代码:
NSLocale *locale = [NSLocale autoupdatingCurrentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *countryName = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
NSLog(@"countryName %@", countryName);
效果很好,但我想知道 countryName
将如何显示,这样我就可以设置 switch case,如果您不知道每个国家/地区的具体情况,这会很困难拼写为:USA、United States、United States of America 等。Apple 是否有国家/地区代码列表,我找不到。
还有没有办法确保结果是英文的?
I want to be able to make the app change depending on the users location. Im using the code below:
NSLocale *locale = [NSLocale autoupdatingCurrentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *countryName = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
NSLog(@"countryName %@", countryName);
which works great, but I want to know how the countryName
's will be displayed, so I can set up switch case's, which is hard if you dont know how exactly each country is spelt: USA, United States, United States of America, etc. Is there a list of countryCode from Apple, I cant find one.
Also is there a way to make sure the result is in English?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Apple 使用 ISO-3166 标准。
Apple uses the ISO-3166 standard.
“ISO 标准 ISO-3166”在大多数情况下是准确的,但请尝试在 iOS 设置中选择“欧洲”作为区域。您将得到返回值“150”。为什么是“150”?似乎是这里的区域代码: http://en.wikipedia.org/wiki/UN_M.49 。或者从这里:http://site.icu-project.org/design /t/territory-region-apis
"ISO standard ISO-3166" is accurate in most cases, but try selecting "Europe" as a region in iOS settings. You will get a return value of "150". Why "150"? Seems like a region code from here: http://en.wikipedia.org/wiki/UN_M.49. Or from here: http://site.icu-project.org/design/t/territory-region-apis
NSLocale
< /a> 从CFLocale
获取数据,后者又获取数据从ICU - Unicode 国际组件(Apple 在此处保留副本)。文件
/icuSources/common/uloc.cpp
几乎包含了我们通常看到的返回信息。但是,
/cldrFiles/supplementalData.xml
可能是主要来源。此文件来自 CLDR - Unicode 通用区域设置数据存储库。NSLocale
gets its data fromCFLocale
which in turn gets its data from theICU - International Components for Unicode (Apple keep copies here). The file
/icuSources/common/uloc.cpp
contains almost all the information we usually see returned.However,
/cldrFiles/supplementalData.xml
may be the primary source. This file comes from the CLDR - Unicode Common Locale Data Repository.