我必须在 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.
在斯威夫特中:
let currentLocale = NSLocale.currentLocale()
let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as? String
如果您想查找当前时区的国家代码,请参阅@chings228 的回答 https://stackoverflow.com/a/8357916/224671.
如果您想查找设备物理位置的国家/地区代码,您将需要具有反向地理编码的 CoreLocation。详细请看这个问题:如何在 iOS 中获取用户的当前位置 https://stackoverflow.com/questions/4152003
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)