Find current country from iPhone device

IosObjective CIphoneApplication SettingsAppsettings

Ios Problem Overview


I have to get the current country in the iPhone settings. Can anyone tell me how to get the current country in iPhone application.

I have to use the current country for parsing the RSS feed in which I need to pass the current country.

Please help me out to find the country .

Thanks in advance.

Ios Solutions


Solution 1 - Ios

To find the country of the user's chosen language:

NSLocale *currentLocale = [NSLocale currentLocale];  // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
// get country code, e.g. ES (Spain), FR (France), etc.

In Swift:

let currentLocale = NSLocale.currentLocale()
let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as? String

If you want to find the country code of the current timezone, see @chings228's answer.

If you want to find the country code of the device's physical location, you will need CoreLocation with reverse geocoding. See this question for detail: https://stackoverflow.com/questions/4152003

Solution 2 - Ios

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

Solution 3 - Ios

For devices with SIM card you can use this:

  CTTelephonyNetworkInfo * network_Info = [CTTelephonyNetworkInfo new];
  CTCarrier * carrier = network_Info.subscriberCellularProvider;
  NSString  * countryCode = [carrier.isoCountryCode uppercaseString];

Solution 4 - Ios

For Swift 4.0,

You can simply use

let countryCode = Locale.current.regionCode

print(countryCode)

Solution 5 - Ios

NSLocale *countryLocale = [NSLocale currentLocale];  
NSString *countryCode = [countryLocale objectForKey:NSLocaleCountryCode];
NSString *country = [countryLocale displayNameForKey:NSLocaleCountryCode value:countryCode];
NSLog(@"Country Code:%@ Name:%@", countryCode, country);
//Country Code:IN Name:India

Source Link.

Solution 6 - Ios

If you're testing and want to use a different language from your system, it's easiest to change your scheme's Application Language and Application Region options instead of changing the language and region on your device or simulator.

Go to Product->Scheme->Edit Scheme...->Run->Options and choose the Application Language and Application Region you want to test.

Edit Application Language and Application Region within Scheme Run Options

From the iOS Documentation: Testing Your Internationalized App

Solution 7 - Ios

NSTimeZone *gmt = [NSTimeZone localTimeZone];
    
NSLog(@"timezone gmt %@",gmt.abbreviation);

Solution 8 - Ios

Swift 3.0 latest working code is

if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
    print(countryCode)
}

Solution 9 - Ios

Swift 3.0 solution

if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
            print(countryCode)
        }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAppAspectView Question on Stackoverflow
Solution 1 - IoskennytmView Answer on Stackoverflow
Solution 2 - IosSachindra PandeyView Answer on Stackoverflow
Solution 3 - Iosuser2248258View Answer on Stackoverflow
Solution 4 - IosMehul ThakkarView Answer on Stackoverflow
Solution 5 - IosTeja Kumar BethinaView Answer on Stackoverflow
Solution 6 - IosHeath BordersView Answer on Stackoverflow
Solution 7 - Ioschings228View Answer on Stackoverflow
Solution 8 - IosMuhammad NayabView Answer on Stackoverflow
Solution 9 - IosSourabh SharmaView Answer on Stackoverflow