Bor*_* Y. 6 storekit in-app-purchase ios swift ios9
RayWenderlich 博客说,检查是否启用了应用内购买以正确阻止 UI 很重要:
Apple 要求您优雅地处理这种情况;不这样做可能会导致应用程序被拒绝。
当您禁用应用内购买时,限制SKPaymentQueue.canMakePayments()应该会返回,false但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)
}
}
Run Code Online (Sandbox Code Playgroud)
JSA*_*986 -2
您需要检查您的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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3673 次 |
| 最近记录: |