我必须在iPhone设置中获取当前国家/地区.有谁能告诉我如何在iPhone应用程序中获取当前的国家信息吗.
我必须使用当前国家解析RSS提要,我需要在其中传递当前国家.
请帮我找到这个国家.
提前谢谢.
我必须在iPhone设置中获取当前国家/地区.有谁能告诉我如何在iPhone应用程序中获取当前的国家信息吗.
我必须使用当前国家解析RSS提要,我需要在其中传递当前国家.
请帮我找到这个国家.
提前谢谢.
要查找用户所选语言的国家/地区:
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's answer.
如果你想找到设备物理位置的国家代码,你需要使用反向地理编码的CoreLocation.详见此问题:How can I get current location from user in iOS