xcode 获取用户的国家

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5095814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:18:22  来源:igfitidea点击:

Get User's Country

iphoneobjective-cxcodeios4localization

提问by max_

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

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

回答by

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]];

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.

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