Get Timezone/country from iPhone Get Timezone/country from iPhone ios ios

Get Timezone/country from iPhone


You can get the name of the local time zone using:

NSTimeZone *timeZone = [NSTimeZone localTimeZone];NSString *tzName = [timeZone name];

The name will be something like Australia/Sydney, or Europe/Zurich, or America/Denver. Since it sounds like you might only care about the continent, that might be all you need.

If you need more: Get the official time zone database at http://www.iana.org/time-zones. Download tzdata2013g.tar.gz (or whatever the most recent version of tzdataYYYYx.tar.gz is when you're reading this). There's a file in that archive named zone.tab that gives a lat/long for each time zone, for example:

CH      +4723+00832     Europe/Zurich

The +4723+00832 indicates latitude = +47º23", longitude = +8º23".

Update: In some cases (I'm not sure which), the time zone name may be an older-style name like US/Pacific that isn't listed in zone.tab. To handle those, also get the file called backward, which gives translations of older names to current names.

Converting zone.tab into something your app can use is up to you. The results will be nowhere near as accurate as location services, but will give a general idea. But it's not guaranteed. It will fail in a couple of situations:

  1. The user changes their time zone in Settings. Most users let their phone set the time and zone automatically, but not everyone. If the user changes their time zone, you'll get whatever they want instead of what's accurate.

  2. The device is unable to determine the correct local time zone. Network problems might prevent the phone from setting the time and zone accurately. For example, if the user travels by plane and has network problems when they land, the phone may still show the time zone from their departure location.


Update: I am changing my answer after the last comment.

You can reverse lookup for IP of the phone to find out geo location. There are several rest APIs available.

Saying that I don't recommend this as this may cause Apple to reject your application. Safe bet is to go thru Apple-provided location services


    NSTimeZone *timeZoneLocal = [NSTimeZone localTimeZone];    NSString *strTimeZoneName = [timeZoneLocal name];    or    NSTimeZone *timeZoneLocal = [NSTimeZone defaultTimeZone];    NSString *strTimeZoneName = [timeZoneLocal name];


matomo