仅购买iAP一次

时间:2016-02-11 11:55:03

标签: ios swift

我有一个UIButton,我可以请求用户使用该代码购买iAP:

但如果快速按下按钮不止一次,则每次取消购买时都会显示UIAlertView。 评论是否需要iAP代码的大部分内容。 如何一次只显示一次?

@IBAction func book(sender: UIButton) {
         self.buyConsumable()
    }


    func buyConsumable(){
         if (SKPaymentQueue.canMakePayments())
        {
            let productID:NSSet = NSSet(object: self.productID!);
            let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>);
            productsRequest.delegate = self;
            productsRequest.start();
        }else{

        }
    }
...

1 个答案:

答案 0 :(得分:0)

试试这个:

@IBAction func book(sender: UIButton) {

     sender.enabled = false
     self.buyConsumable()
}


func buyConsumable(){
     if (SKPaymentQueue.canMakePayments())
    {
        let productID:NSSet = NSSet(object: self.productID!);
        let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>);
        productsRequest.delegate = self;
        productsRequest.start();
    }else{

    }
}

付款完成后 sender.enabled = true