我在控制器中移动时显示本地化的应用内购买价格

时间:2017-09-03 05:29:43

标签: ios swift in-app-purchase uialertview

我想在我的控制器中移动时显示本地化的价格。

我使用此代码:

if (SKPaymentQueue.canMakePayments())
            {
                let productID:NSSet = NSSet(object: self.product_id!)
                let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
                productsRequest.delegate = self
                productsRequest.start()
                print("Fetching Products")
            }else{
                print("Can't make purchases")
            }

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

    let count : Int = response.products.count
    if (count>0) {
        let validProduct: SKProduct = response.products[0] as SKProduct
        if (validProduct.productIdentifier == self.product_id) {
            buyProduct(product: validProduct);

        } else {
            print(validProduct.productIdentifier)
        }
    } else {
        print("nothing")
    }
}

func buyProduct(product: SKProduct){
    price = localizedPriceForProduct(product)
    let payment = SKPayment(product: product)
    SKPaymentQueue.default().add(payment);
    self.loading.stopAnimating()
}

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)!
}

但是在这种情况下,我在商店中看到UIAlertView登录。如何修复它并消失这个UIAlertView?

0 个答案:

没有答案