获取用户的国家/地区 [英] Get User's Country

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

问题描述

我只是想知道如何使用Xcode(iPhone Dev SDK)找出当前用户的国家。

I just wanted to know how I could find out the current user's country using Xcode (iPhone Dev SDK).

推荐答案

如果你想获得用户所在的国家,你可以做两件事。最简单的方法是将其从本地化设置中删除。

If you want to get the users country you can do two things. The easiest is to deciper it from their localization settings.

NSLocale *locale = [NSLocale currentLocale];
NSString *country = [locale displayNameForKey:NSLocaleIdentifier value:[locale localeIdentifier]];

这可能是不可靠的(例如在国外的用户)。如果您依赖于这些信息,则应使用CoreLocation查找用户当前位置,然后使用反向地理标记从坐标中获取国家/地区。请查看 CoreLocation框架参考。它应该对你有所帮助。

This can be unreliable (e.g. a user who is abroad). If you depend on the information you should use CoreLocation to find the users current location and then use reverse geo-tagging to get the country from the co-ordinates. Take a look at the CoreLocation Framework reference. It should help you.

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

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