Search current country from iPhone device

I need to set the current country in the iPhone settings. Can someone tell me how to get the current country in the iPhone app.

I need to use the current country to parse the RSS feed in which I need to transfer the current country.

Please help me find a country.

Thanks in advance.

+45
ios objective-c iphone application-settings
Oct 15 '10 at 8:27
source share
8 answers

To find the country of the user selected language:

NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, eg 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 time zone, see @ chings228 answer .

If you want to find the country code on the physical location of the device, you will need CoreLocation with reverse geocoding. See this question for details: How to get the current location from a user in iOS .

+124
Oct 15 '10 at 8:32
source share
 NSLocale *locale = [NSLocale currentLocale]; NSString *countryCode = [locale objectForKey: NSLocaleCountryCode]; NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode]; 
+16
May 19 '12 at 11:21
source share
 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 .

+9
Mar 17 '15 at 10:51
source share

If you are testing and want to use a different language from your system, the easiest way is to change the settings of the Application Language and Application Region scheme instead of changing the language and region on your device or simulator.

Go to Product Scheme Edit Scheme... Run Options and select the Application Language and Application Region tags that you want to check.

Change the application language and application area within the scheme launch parameters

From iOS documentation: Testing your internationalized application

+4
Dec 11 '15 at 22:07
source share
 NSTimeZone *gmt = [NSTimeZone localTimeZone]; NSLog(@"timezone gmt %@",gmt.abbreviation); 
+3
Dec 02 2018-11-12T00:
source share

Swift 3.0 solution

 if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String { print(countryCode) } 
+3
Oct 19 '16 at 8:57
source share

For devices with a SIM card, you can use this:

  CTTelephonyNetworkInfo * network_Info = [CTTelephonyNetworkInfo new]; CTCarrier * carrier = network_Info.subscriberCellularProvider; NSString * countryCode = [carrier.isoCountryCode uppercaseString]; 
+3
Apr 6 '17 at 11:53 on
source share

Latest working Swift 3.0 code

 if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String { print(countryCode) } 
+1
Jul 07 '17 at 13:52
source share



All Articles