SKPaymentQueue.canMakePayments()始终返回true

时间:2015-09-17 19:33:17

标签: ios swift in-app-purchase ios9 storekit

重要的是要检查是否启用了应用内购买以正确阻止用户界面,RayWenderlich博客说:

  

Apple要求您优雅地处理这种情况;不这样做可能会导致拒绝应用。

当您停用应用内购买时,限制SKPaymentQueue.canMakePayments()应返回false,但无论如何都会返回true。我尝试了两个不同的项目,包括this one from RayWenderlich.

我仅使用iOS 9对此进行了测试。

如何识别使用家长限制禁用应用内购买?

更新
有人要求分享我的代码。我认为没有必要,代码很明显,没有错误。我也可以用Ray的项目重现这个问题。

// This function is called in from viewDidLoad()
// And after SKProduct is updated.
func addTextFromProduct(p: SKProduct) {

    if let title = p.localizedTitle as String? {
        self.navigationBar.topItem?.title = title
    }

    if let description = p.localizedDescription as String? {
        if dailyLimit {
            self.informationLabel.text? = "\(waitingTime)\(description)"
        } else {
            self.informationLabel.text? = "\(description)"
        }

        if SKPaymentQueue.canMakePayments() {
            unblockButtons()
        }

    } else {
        self.informationLabel.text? = "\(waitingTime)\(description)\n\nIn-App Purchase is unavailable at this moment."
        blockButtons()
    }

    if SKPaymentQueue.canMakePayments() {
        self.priceFormatter.locale = p.priceLocale
        let localPrice: String! = self.priceFormatter.stringFromNumber(p.price)
        let label = "\(localPrice)"
        self.buyButton.setTitle(label, forState: UIControlState.Normal)
    } else {
        blockButtons()
        buyButton.setTitle("Not Available", forState: UIControlState.Disabled)
    }
}

2 个答案:

答案 0 :(得分:2)

I have same problem. Maybe this will help you.
https://forums.developer.apple.com/thread/22312
I also think it seems like a bug.
I tested this with iOS 7.1.2 and 8.4.1. SKPaymentQueue.canMakePayments() returns false even when "In-App Purchases" is off and "Installing Apps" is on.

答案 1 :(得分:-1)

如果用户启用了IAP,您需要签入viewDidLoad方法。

if(SKPaymentQueue.canMakePayments()) {

            print("IAP is enabled, loading")

            // Your Products


            let request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
            request.delegate = self
            request.start()



        }
        else {

         print("IAP not allowed")  
         //Do something like show an alert, the user has not allowed in app purchases

       }