从iPhone获取时区/国家/地区 [英] Get Timezone/country from iPhone

查看:170
本文介绍了从iPhone获取时区/国家/地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何都要告诉手机所在的时区/国家/地区?我宁愿不使用位置服务。

Is there anyway to tell which timezone/country the phone is located in? I would prefer not to use location services.

这样做的目的是自动路由呼叫。如果用户在美国,我希望该应用默认为呼叫美国呼叫中心。如果用户在其他国家/地区,我希望它默认为其呼叫中心。

The purpose of this is to automatically route calls. If the user is in the US, I want the app to default to calling the US based call center. If the user is in another country, I want it to default to their call center.

谢谢!

推荐答案

你可以得到当地的名字时区使用:

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

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

名称将类似澳大利亚/悉尼,或欧洲/苏黎世,或 America / Denver 。因为听起来你可能只关心这个大陆,这可能就是你所需要的。

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.

如果你需要更多:在 http://www.iana.org/time-zones 。下载 tzdata2013g.tar.gz (或者无论最新版本的 tzdataYYYYx.tar.gz 是什么时候你读这个)。该档案中有一个名为 zone.tab 的文件,它为每个时区提供一个纬度/经度,例如:

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

+ 4723 + 00832 表示纬度= +47º23,经度= +8º23。

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

更新:在某些情况下(我不确定哪个),时区名称可能是 US / Pacific 之类的旧式名称,未列在 zone.tab 。要处理这些,还要获取名为的文件,它将旧名称的翻译提供给当前名称。

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.

转换 zone.tab 您的应用可以使用的内容取决于您。结果将远远不如位置服务那么准确,但会给出一个大致的想法。但不能保证。它会在以下两种情况下失败:

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. 用户在设置中更改其时区。大多数用户让他们的手机自动设置时间和区域,但不是每个人。如果用户更改了他们的时区,您将获得他们想要的任何内容而不是准确的内容。

  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.

设备无法确定正确的本地时区。网络问题可能会阻止手机准确设置时间和区域。例如,如果用户乘飞机旅行并在登陆时遇到网络问题,则手机可能仍会显示出发地点的时区。

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.

这篇关于从iPhone获取时区/国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆