从iPhone设备查找当前国家/地区 [英] Find current country from iPhone device
问题描述
我必须在iPhone设置中获取当前国家/地区。任何人都可以告诉我如何在iPhone应用程序中获取当前国家/地区。
I have to get the current country in the iPhone settings. Can anyone tell me how to get the current country in iPhone application.
我必须使用当前国家/地区来解析我需要通过当前国家/地区的RSS Feed 。
I have to use the current country for parsing the RSS feed in which I need to pass the current country.
请帮我找到国家。
提前致谢。
推荐答案
要查找用户所选语言的国家/地区:
To find the country of the user's chosen language:
NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
// get country code, e.g. ES (Spain), FR (France), etc.
在Swift:
let currentLocale = NSLocale.currentLocale()
let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as? String
如果要查找当前时区的国家/地区代码,请参阅 @ chings228的回答。
If you want to find the country code of the current timezone, see @chings228's answer.
如果要查找设备物理位置的国家代码,您将需要具有反向地理编码的CoreLocation。有关详细信息,请参阅此问题:如何从iOS中获取用户的当前位置
If you want to find the country code of the device's physical location, you will need CoreLocation with reverse geocoding. See this question for detail: How can I get current location from user in iOS
这篇关于从iPhone设备查找当前国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!