Reputation: 115
I have 4 non-consumables in my application and the purchasing of these works without any problems.
However, I have created a restorePurchases button which restores all products regardless of whether the user has purchased them or not. I've tested this on 4 different sand box test users, and the results are consistent (i.e. for a test user who has never bought the non consumables, clicking 'restore' restores all products)
My restore code looks like:
@IBAction func restorePurchases(sender: UIButton) {
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}
func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue) {
print("transactions restored")
for transaction in queue.transactions {
let t: SKPaymentTransaction = transaction
let prodID = t.payment.productIdentifier as String
switch prodID {
case "productAbc1":
defaults.setBool(true , forKey: "productAbc1")
case "productAbc2":
defaults.setBool(true , forKey: "productAbc2")
case "productAbc3":
defaults.setBool(true , forKey: "productAbc3")
case "productAbc3":
defaults.setBool(true , forKey: "productAbc4")
default:
print("IAP not setup; enable it")
}
}
}
Do I need to be checking additional parameters in paymentQueueRestoreCompletedTransactionsFinished? Comparing my code to many other similar questions / IAP examples, it looks pretty much the same. Is this an issue with the sandbox environment or code?
Upvotes: 0
Views: 496
Reputation: 115
queue.finishTransaction(transaction)
for each case was missing; meaning they were never clearing from the queue. So the next time I attempted to restore the purchases, all previous transactions were found (and restoring).
Adding the above line of code resolved the issue.
Upvotes: 1