7

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?

daihovey
  • 3,485
  • 13
  • 66
  • 110

3 Answers3

10

Apple uses the ISO-3166 standard.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
Matt S.
  • 13,305
  • 15
  • 73
  • 129
  • -1: Link-only answers are poor answers because the link can be broken (as this currently is). You should include the relevant information *within your answer* and a link to the original page/info as an additional resource or attribution. – JRG-Developer Oct 24 '14 at 20:11
  • In Great Britain [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]; returns 'GB' which is not in the ISO-3166 list (it's not a country!) – public static void Jan 13 '16 at 18:03
  • In Swift, NSLocale.ISOCountryCodes() – Andrew Johnson Aug 27 '16 at 17:51
7

"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

Yevgeni Litvin
  • 450
  • 4
  • 8
2

NSLocale gets its data from CFLocale which in turn gets its data from the ICU - 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.

jjrscott
  • 1,386
  • 12
  • 16