【发布时间】:2018-05-06 14:17:32
【问题描述】:
目前我正在使用 Swift 开发 iOS 应用程序。我启用了 InApp Purchased。付款做得很好,但是当我显示来自 iTunes Connect 的数据时,每月订阅数据显示完美,但我希望以每月格式在年度选项卡上显示价格并提供一些折扣,当用户点击卡时,它应该显示年度价格。我无法做到这一点。图片中显示的说明。提前致谢。
// Currently i am getting product info with this method
// MARK: - REQUEST IAP PRODUCTS
func productsRequest (_ request:SKProductsRequest, didReceive response:SKProductsResponse) {
if (response.products.count > 0) {
iapProducts = response.products
// showHUD("Loading...")
let indexPath = IndexPath.init(row: 0, section: 0)
guard let cell = collectionView.cellForItem(at: indexPath) as? CollectionViewCell else { return }
let numberFormatter = NumberFormatter()
let firstProduct = response.products[0] as SKProduct
print("localizedDescription", firstProduct.localizedDescription)
print("localizedTitle", firstProduct.localizedTitle)
// Get its price from iTunes Connect
numberFormatter.formatterBehavior = .behavior10_4
numberFormatter.numberStyle = .currency
numberFormatter.locale = firstProduct.priceLocale
let price1Str = numberFormatter.string(from: firstProduct.price)
// Show its description
cell.monthlyLabel.text = "\(firstProduct.localizedTitle)"
cell.rupeesLabel.text = "\(price1Str!)"
cell.perMonthLabel.text = "\(firstProduct.localizedDescription)"
let indexPath1 = IndexPath.init(row: 1, section: 0)
guard let cell2 = collectionView.cellForItem(at: indexPath1) as? CollectionViewCell else { return }
let secondProd = response.products[1] as SKProduct
// Get its price from iTunes Connect
numberFormatter.locale = secondProd.priceLocale
let price2Str = numberFormatter.string(from: secondProd.price)
// Show its description
cell2.monthlyLabel.text = "\(secondProd.localizedTitle)"
cell2.rupeesLabel.text = "\(price2Str!)"
cell2.perMonthLabel.text = "\(secondProd.localizedDescription)"
// ------------------------------------
}
}
【问题讨论】:
-
不清楚你在问什么。您应该简单地显示在 iTunesConnect 中配置的价格,这就是您似乎正在做的事情。显示年度购买的月度价格是一种误导
-
感谢 Paulw115 的回复。请看我编辑的问题。
-
所以写代码来说明这一点。您需要将年度产品的价格除以 12。注意四舍五入,因为 $4.99 * 12 实际上是 $59.88,这就是为什么我说它有点误导。
-
是的,但我找不到确切的代码。
-
基本上是
secondProd.price / 12。
标签: ios swift3 in-app-purchase