我试图以多种货币显示应用程序内采购的价格。用户一次可以选择1项、2项或3项。价格在运行时自我更新(例如,用户选择一个项目,而不是选择2个),这样用户就可以看到它正在更新。如果价格仅以美元显示,这是相当容易实现的。当加入欧元或英国国标时,事情就开始变得混乱起来。如何动态地以多种货币显示IAP价格?
发布于 2015-09-12 12:22:05
像这样的东西应该对你有用。下面的代码打印本地化的标题、货币代码和价格。
let product = ... //your SKProduct
if let currencyCode = product.priceLocale.objectForKey(NSLocaleCurrencyCode) as? String {
print(product.localizedTitle + " : " + currencyCode + " \(product.price)")
}发布于 2015-09-12 13:05:05
这是我使用的函数。当您在世界上某个不受支持的商店时,SKProduct的某些属性似乎没有被填充。
internal func getPrice(#priceLocale: NSLocale!, price: NSDecimalNumber, count: Int) -> String? {
let formatter = NSNumberFormatter()
formatter.formatterBehavior = NSNumberFormatterBehavior.Behavior10_4
formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle
formatter.locale = priceLocale
return formatter.stringFromNumber(price * count)
}这是我使用的函数(实际上是extension SKProduct中的一个属性),如果格式化count或price出错,它将返回count。
https://stackoverflow.com/questions/32538131
复制相似问题