如何获取用户的国家/地区信息 [英] How to get user's country information

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

问题描述

基本上我需要在应用程序启动时识别用户的国家/地区,并根据他/她的国家/地区在我的应用中启用或停用基于位置的功能。我需要在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??

推荐答案

您是否需要设备所在国家/地区的名称?应用程序运行时位于?

Do you need the name of the country that the device is physically located in while the app is running?

或者您可以使用设备使用的系统区域设置,例如en_US或fr_CA吗?

Or could you make do with the system locale the device is using such as en_US or fr_CA ?

如果是后者,你可以:

NSLocale *currentUsersLocale = [NSLocale currentLocale];  
NSString *currentLocaleID = [currentUsersLocale localeIdentifier];`

然后 currentLocaleID en_USfr_CA或类似。

否则,您需要使用CoreLocation和某种形式的反向地理编码器将您的纬度/经度转换为国家/地区名称。

Otherwise you'll need to use CoreLocation and some form of Reverse Geocoder to convert your lat/long into a country name.

MKReverseGeocoder可以做到这一点但是服务条款说你需要和谷歌地图一起做这件事,这可能不适合你。仅适用于OS 3.0及更高版本,请搜索 MKReverseGeocoder 的文档以获取更多信息。

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.

我自己需要这个并最终在PHP中进行地理编码在我们的服务器上,使用设备IP地址。这是基本的,但为我们提供了足够的详细信息。

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.

查看这个网络服务: http://ws.geonames.org/findNearby?lat=47.3&lng=9

哪个返回带有国家和附近地名的XML文档,给定一个lat / lng对。

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.

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

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