2015-09-17 205 views
4

检查是应用内购买才能正常阻塞UI,RayWenderlich博客说,这是很重要的:SKPaymentQueue.canMakePayments()总是返回true

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

当禁用应用程序内购买,这些限制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) 
    } 
} 
+1

我在iOS的早期版本中遇到了同样的问题,但是如果InAppPurchases受限,canMakePayments会正确返回false,但是在iOS 9上它似乎反映了安装应用程序限制? – Michael

+0

已确认,Xcode 7.2.1,iOS 9.2.1,已启用ARC的canMakePayments只会在加载应用程序后限制安装应用程序时返回false。以下是有关如何设置和使用限制的有用链接:https://support.apple.com/en-us/HT204396。有关此问题的任何更新? –

回答

-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 

     } 
+0

是的,我知道这一点,我的问题是我的应用程序认为应用内购买已启用,即使我在设置>常规>限制中禁用了它们。 –

+0

如果你知道这个,然后发布一些代码,以便人们可以帮助你。如果你有这个代码实现发布它会告诉我们。如果你想要帮助显示你迄今为止做了什么,并尝试 – JSA986

+0

JSA986,我更新了我的问题。 –

2

我有同样的问题。也许这会帮助你。
https://forums.developer.apple.com/thread/22312
我也觉得它看起来像一个错误。
我用iOS 7.1.2和8.4.1测试了这个。即使关闭“应用内购买”并启用“安装应用”,SKPaymentQueue.canMakePayments()也会返回false。