SKPaymentQueue.canMakePayments () always returns true

It’s important to check if app purchases are enabled in the app to block the user interface, the RayWenderlich blog says:

Apple demands that you handle this situation gracefully; this will not lead to a rejection of the application.

When you turn off the in-app purchase, restrictions SKPaymentQueue.canMakePayments()should return false, but it always returns trueno matter what. I tried with two different projects, including this one from RayWenderlich.

I tested this only with iOS 9.

How do I know if in-app purchases are disabled with parental restrictions?

Update
Someone asked to share my code. I do not think this is necessary, the code is obvious and has no errors. I can also reproduce these issues with the Ray project.

// 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)
    }
}
+4
source share
2 answers

I have the same problem. Perhaps this will help you.
https://forums.developer.apple.com/thread/22312
I also think this seems like an error.
I tested this with iOS 7.1.2 and 8.4.1. SKPaymentQueue.canMakePayments () returns false even when "In-App Purchases" is disabled and "Install Applications" is turned on.

+2
source

viewDidLoad, IAP.

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

       }
-1

Source: https://habr.com/ru/post/1607896/


All Articles