繁体   English   中英

SKPaymentQueue.canMakePayments() 总是返回 true

[英]SKPaymentQueue.canMakePayments() always returns true

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

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

当您禁用应用内购买时,限制SKPaymentQueue.canMakePayments()应该返回falseSKPaymentQueue.canMakePayments()它总是返回true 我尝试了 2 个不同的项目,包括这个来自 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)
    }
}

我有同样的问题。 也许这会对你有所帮助。
https://forums.developer.apple.com/thread/22312
我也认为这似乎是一个错误。
我用iOS 7.1.2和8.4.1测试了这个。 即使“应用程序内购买”已关闭且“安装应用程序”已启用,SKPaymentQueue.canMakePayments()也会返回false。

如果用户已启用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

       }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM