【发布时间】:2018-10-23 21:22:10
【问题描述】:
我正在使用SwiftyStoreKit 在我的项目中实施 iAP。我有一个用户可以购买和恢复的自动更新订阅。这似乎工作正常,但是在检索要显示到 UI 的产品信息时遇到问题。
我正在尝试显示本地化价格,返回的价格是年度成本,因此我需要将该数字除以 12 以将其显示为每月成本。但是,在获取价格并尝试恢复价值时,出现以下错误:
void 函数中出现意外的非 void 返回值
设置按钮值
let subscribeButton = subscriptionManager.getSubscriptionPricePerMonth(isYearly: false)
subscribeButton(monthlyCost, for: .normal)
检索价格
//Get prices
func getSubscriptionPricePerMonth() -> String {
let productId = getProductId()
NetworkActivityIndicatorManager.networkOperationStarted()
SwiftyStoreKit.retrieveProductsInfo([productId]) { result in
NetworkActivityIndicatorManager.networkOperationFinished()
if let product = result.retrievedProducts.first {
let priceString = product.localizedPrice!
return priceString
} else if let invalidProductId = result.invalidProductIDs.first {
//return ("Could not retrieve product info", message: "Invalid product identifier: \(invalidProductId)")
print("Could not retrieve product info\(invalidProductId)")
} else {
let errorString = result.error?.localizedDescription ?? "Unknown error. Please contact support"
//return ("Could not retrieve product info, \(errorString)")
print("\(errorString)")
}
}
}
【问题讨论】:
标签: swift in-app-purchase storekit swiftystorekit