I am currently getting the NSLocaleCountryCode by
NSLocale *currentLocale = [NSLocale currentLocale]; NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
Now, the problem is if the iPhone or iPad is bought from a certain country and the user moves into a different country. The NSLocaleCountryCode returns the value of the country where the device is bought. Is there a way to get the Current NSLocaleCountryCode?
Asked
Active
Viewed 627 times
-1

drbj
- 113
- 9
-
1The `NSLocaleCountryCode` has nothing to do with where the device was purchased or where it is currently located. It is based on the setting in the Settings app for General, Language & Region, Region. – rmaddy Jul 18 '16 at 05:40
-
What do you mean by the "current" country code? What exactly are you trying to get? – rmaddy Jul 18 '16 at 05:41
-
@rmaddy For example, the device is bought in US. So the NSLocaleCountryCode is set to US right? Then the user moves to another country say Canada. And I am trying to get CA, the "current" country code of the phone – drbj Jul 18 '16 at 06:01
-
Without the user changing his/her Region in the settings. Should I use different function? – drbj Jul 18 '16 at 06:03
-
You are still being unclear. Do you want to know the country that the device is physically in at the moment? If so, use Core Location and get the user's current location (If the user allows your app to do so). – rmaddy Jul 18 '16 at 15:45
1 Answers
3
NSLocale
is just a setting about currently used regional settings, it doesn't mean the actual country you're in.
Use CLLocationManager
to get current location and use CLGeocoder
to perform reverse-geocoding. You can get country name from CLGeocoder
.
if you need the additional help see this alternate way
Updated answer
CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];
[reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
// NSLog(@"Received placemarks: %@", placemarks);
CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];
NSString *countryCode = myPlacemark.ISOcountryCode;
NSString *countryName = myPlacemark.country;
NSString *cityName= myPlacemark.subAdministrativeArea;
NSLog(@"My country code: %@ and countryName: %@ MyCity: %@", countryCode, countryName, cityName);

Community
- 1
- 1

Anbu.Karthik
- 82,064
- 23
- 174
- 143
-
@drbj - check the updated answer, and sample link https://ktrkathir.wordpress.com/2014/12/31/get-city-country-name-from-latitudelongitude-by-using-clgeocoder-in-ios/ – Anbu.Karthik Jul 18 '16 at 05:48
-
-
@drbj - using CLLOcation Manager u get the location using `- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray
*)locations` – Anbu.Karthik Jul 18 '16 at 05:54 -
-
cna you updated the question once bro, I think you confused little bit – Anbu.Karthik Jul 18 '16 at 05:59
-
-
correct bro , but `NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];` not given update loaction bro – Anbu.Karthik Jul 18 '16 at 06:03
-