ios - 无法获取当前位置货币 localIdentifier

标签 ios swift

Using iOS Swift, Xcode 7.1, iOS 9

我想在我的产品费用中向应用用户显示当前位置的货币符号。

我正在使用以下代码:

let price = 20.00
let formatter = NSNumberFormatter()
formatter.locale = NSLocale.currentLocale() 
formatter.numberStyle = .CurrencyStyle
print(formatter.stringFromNumber(price)!) // $20.00

但是我得到的货币是美元。由于我在印度使用该设备, NSLocale.currentLocale 不应该给我卢比货币吗?

我还在 Playground 上尝试了以下操作

let currency = String(NSLocale.currentLocale().localeIdentifier) // "en_US"

但这也显示了美国标识符。

那么谁能告诉我如何根据用户当前位置获取货币符号?

最佳答案

NSLocale 基于您的设备设置

Settings -> General -> Language Region

在您的情况下,您必须使用特定于 iOS 的核心位置来获取用户当前位置,然后根据该位置确定货币。

关于ios - 无法获取当前位置货币 localIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33881852/

相关文章:

swift - 如何自定义多个注解?解析-Swift

ios - 切换 UI 元素图形问题

arrays - 检查元类型是否为元素类型为 MyProtocol 的数组

iphone - 如何重新加载 UIVIew 的 UIViewController 数据

ios - NSThread 用于并发操作

ios - 如何计算特定 iPhone 上的像素到点的转换?

ios - AssertMacros.h:预处理程序表达式中预期的行尾

swift - 计时器不会在 CollectionView 中正确更新 Swift

ios - Mapbox iOS SDK 创建曲线 MGLPolyline 和 MKGeodesicPolyline 弄的有些奇怪

ios - 使用 Alamofire 进行简单的发布请求