Blackbeard
Blackbeard

Reputation: 662

Determine country code for iOS Region "Europe"

I am working on an app which asks users for phone number and has a country picker, where the user should input country code.

But while testing null country code values, I found out that somehow my iPhone with iOS 10.2.1 has a region format set to Europe.

The Europe region does not exist in the regions list when I search for it.

When I try to get the current locale country code

NSLocale *currentLocale = [NSLocale currentLocale];
return [currentLocale objectForKey:NSLocaleCountryCode]

I get en_150 which is not useful to determine user's country, at least on my device. Returned country code is 150, which does not exist.

I found a workaround to find to country code by using CTTelephonyNetworkInfo

if(![currentLocale objectForKey:NSLocaleCountryCode]) {
    CTCarrier *carrier = [[CTTelephonyNetworkInfo new] subscriberCellularProvider];
    NSString *countryCode = carrier.isoCountryCode;

    return [countryCode capitalizedString];
}

But how does it work with this Europe locale and why do I have it set like this?

Upvotes: 3

Views: 2313

Answers (1)

Daniel
Daniel

Reputation: 4735

First of all, Europe is a continent not a country. It doesn’t have a country code. It does, however, have a region code. That region code is indeed 150.

Continents have numeric area codes instead including 001 for “World” and 150 for “Europe”.

Be sure to read my article “Are there standard language codes for ‘World English’ and ‘European English’” for a much more detailed explanation. These codes are based in UN M.49, which is the basis for ISO 3166, which is the standard you’re probably thinking of when you say “country codes”.

The problem you’re facing is that you can’t use someone’s language or formatting preferences to determine their physical location. My current device’s locale is en_DK but my physical location is NO. Many devices default to en_US and users all over the world never change the default settings.

Please use CoreLocation to automatically determine the user’s location, or just ask the user to disclose their location.

Upvotes: 1

Related Questions