问题描述
当用户调用restorePurchases()时,即使他们不拥有它,也会恢复非耗材com.premium。
以下是负责恢复购买和购买IAP的功能。这只是非耗材IAP的问题。
购买没有问题。如果用户尝试购买他们已经拥有的IAP,则只需恢复。感谢您查看此内容。
When the user calls restorePurchases(), the non-consumable com.premium is restored even thought they do not own it.Here are the functions that are responsible for the restoring purchases and purchasing IAPs. This is only an issue with non-consumable IAPs.There is no issue with purchasing. And if the user attempts to purchase an IAP that they already have, it is simply restored. Thank you for looking in to this.
func restorePurchases() {
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()
}
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
print("transactions restored")
for transaction in queue.transactions {
let t: SKPaymentTransaction = transaction
let prodID = t.payment.productIdentifier as String
print("starting restoring")
switch prodID {
case "com.premium":
print("restoring ads")
removeAds()
case "com.cash":
print("we dont restore coins")
case "com.level":
print("we dont restore levels")
default:
print("can't restore")
}
}
这也是我的支付队列。
Here is my payment queue also.
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
print("add paymnet")
for transaction:AnyObject in transactions {
let trans = transaction as! SKPaymentTransaction
print(trans.error)
switch trans.transactionState {
case .purchased:
print("buying, ok unlock iap here")
print(p.productIdentifier)
let prodID = p.productIdentifier as String
switch prodID {
case "com.premium":
print("buying ads")
removeAds()
case "com.cash":
print("buying coins")
addCoins()
case "com.level":
print("buying levels")
addLevels()
default:
print("can't buy")
}
queue.finishTransaction(trans)
break;
case .failed:
print("buy error")
queue.finishTransaction(trans)
break;
default:
print("default")
break;
}
}
}
推荐答案
您不应在 paymentQueueRestoreCompletedTransactionsFinished
中更新任何购买状态。此功能只是让您知道恢复过程已完成。您可以使用它来更新UI或显示警报或其他内容。
You should not update any purchase status in paymentQueueRestoreCompletedTransactionsFinished
. This function just lets you know that the restoration process has completed. You could use this to update your UI or display an alert or something.
恢复过程将要恢复的事务传递到 updatedTransactions
函数,您可以在其中处理 .restored
状态与处理 .purchased
状态的方式相同。
The restoration process delivers the transactions to be restored to the updatedTransactions
function where you handle the .restored
state in the same way that you handle the .purchased
state.
基本上恢复只是重放非消费和自动续订订购购买类型的购买交易流程。
Essentially "restore" just replays the purchase transaction process for non-consumable and auto-renewing subscription purchase types.
这篇关于IAP正在恢复尚未购买的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!