ios - SKPaymentQueue.canMakePayments() 总是返回 true

标签 ios swift in-app-purchase ios9 storekit

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

Apple requires that you handle this situation gracefully; not doing so will likely result in an app rejection.

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

最佳答案

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

       }

关于ios - SKPaymentQueue.canMakePayments() 总是返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32638570/

相关文章:

ios - Firebase 为当前用户设置安全和规则

ios - 如何使用 AVCaptureSession 实现像苹果一样的相机应用程序?

java - 在应用内结算(IAB 版本 3)android 中恢复购买

ios - 如何将水平堆栈 View 内的所有按钮拉伸(stretch)为设备宽度

ios - swift - NSFetchRequest 按语法排序

ios - 刷新 iOS IAP 收据以恢复购买即使没有购买也总是返回收据

iphone - iOS 应用内购买安全地恢复以前的购买

ios - 导航和更改导航栏可见性时出现奇怪的 View 效果

ios - 推送通知不显示自定义通知

ios - 如何显示用户定义的位置