gpt4 book ai didi

ios - swift:我的字典中的应用内购买价格

转载 作者:行者123 更新时间:2023-11-30 11:16:55 25 4
gpt4 key购买 nike

我的应用程序中有两项应用内购买。我想加载我的应用内购买价格。

我使用此代码来加载价格:

let productIds = Set(["purchase","purchase1"])
var products = [String:SKProduct]()
var price = [String: String]()

override func viewDidLoad() {
super.viewDidLoad()

if !(UserDefaults.standard.bool(forKey: "purchased")){
if (SKPaymentQueue.canMakePayments()) {
let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productIds);
productsRequest.delegate = self;
productsRequest.start();
print("Fetching Products");
} else {
print("Can't make purchases");
}
}

}

func productsRequest (_ request: SKProductsRequest, didReceive response: SKProductsResponse) {

for product in response.products {
self.products[product.productIdentifier] = product

price[product.productIdentifier] = localizedPriceForProduct(product)
print(price)
}
}

func localizedPriceForProduct(_ product:SKProduct) -> String {
let priceFormatter = NumberFormatter()
priceFormatter.formatterBehavior = NumberFormatter.Behavior.behavior10_4
priceFormatter.numberStyle = NumberFormatter.Style.currency
priceFormatter.locale = product.priceLocale
return priceFormatter.string(from: product.price)!
}

但是在价格中我得到这个结果

["purchase": "3,00 USD"]
["purchase": "3,00 USD", "purchase1": "1,00 USD"]

但我需要得到这个:

["purchase": "3,00 USD", "purchase1": "1,00 USD"]

怎么做?

最佳答案

您正在 for 循环内打印,因此您的代码是正确的,只是打印位于错误的行中。

尝试:

for product in response.products {
self.products[product.productIdentifier] = product

price[product.productIdentifier] = localizedPriceForProduct(product)
}
print(price)

关于ios - swift:我的字典中的应用内购买价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51655554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com