如何获取用户的国家信息
基本上,我需要在应用程序启动时识别用户所在的国家/地区,并根据他/她的国家/地区在我的应用程序中启用或禁用基于位置的功能。我需要在加载 RootViewController 之前在应用程序委托中尽快执行此操作。无论如何,iPhone SDK 中有这样做的吗?
Basically I need to identify the user's country at application startup and enable or disable a location based feature in my app based on his/her country. I need to do this as quickly as possible in the application delegate prior to the RootViewController's loading. Is there anyway of doing this in the iPhone SDK??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否需要应用程序运行时设备实际所在的国家/地区名称?
或者您可以使用设备正在使用的系统区域设置(例如 en_US 或 fr_CA )吗?
如果是后者,您可以:
那么
currentLocaleID
将是"en_US"
或"fr_CA"
或类似的。否则,您将需要使用 CoreLocation 和某种形式的反向地理编码器将您的纬度/经度转换为国家/地区名称。
MKReverseGeocoder 可以做到这一点,但服务条款规定您需要与 Google 地图结合使用,这可能不适合您。仅适用于 OS 3.0 及更高版本,请搜索 MKReverseGeocoder 文档以获取更多信息。
我自己需要这个,最终在我们的服务器上使用设备 IP 地址用 PHP 进行地理编码。它很简陋,但为我们提供了足够的细节来满足我们的需求。
查看此网络服务:http://ws.geonames.org/findNearby ?lat=47.3&lng=9
它返回一个 XML 文档,其中包含给定 lat/lng 对的国家/地区和附近的地名。
不过,该方法依赖于具有活动数据连接的设备。
Do you need the name of the country that the device is physically located in while the app is running?
Or could you make do with the system locale the device is using such as en_US or fr_CA ?
If the latter, you can:
Then
currentLocaleID
will be"en_US"
or"fr_CA"
or similar.Otherwise you'll need to use CoreLocation and some form of Reverse Geocoder to convert your lat/long into a country name.
MKReverseGeocoder can do this but the terms of service say you need to be doing it in conjunction with a Google map which may not suit you. Only available on OS 3.0 and above, search the documentation for MKReverseGeocoder for more info.
I needed this myself and ended up doing Geocoding in PHP on our server, using the device IP address. It's rudimentary, but gave us enough detail for our needs.
Check out this web service: http://ws.geonames.org/findNearby?lat=47.3&lng=9
Which returns an XML doc with country and nearby place names given a lat/lng pair.
That approach relies on the device having an active data connection though.