Restoring multiple purchases

Hello,

So i have a problem.

I have 2 in-app purchases, both non-consumables. I can buy them and everything, but when it comes to restoring them is where it gets screwy.

When i create a new sandbox tester and hit my restore purchase button, it calls the restore purchases function but i hadnt made any purhcases on that account. And i do not know how to make it check which in app purchase has already been purchased, and which part of the code to call based on this finding.

This is the code I call when i click the restore button:



}else if nodeArray.first?.name == "Restore"{

if SKPaymentQueue.canMakePayments() == true{

SKPaymentQueue.default().add(self)

SKPaymentQueue.default().restoreCompletedTransactions()

}


and heres the restore func



func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {

for transaction in queue.transactions {

let t: SKPaymentTransaction = transaction

let prodID = t.payment.productIdentifier as String

switch prodID {

case "com.Carawind.FlipFlop.RemoveAds":

AdBtn = true

UserDefaults.standard.set(true, forKey: "RemovedAds")

RemoveAdsBtn.removeFromParent()

self.viewController.HideAds()

break

default:

break

}

}

}


I havent added the other in app purchase to this function but how do I make it decide which in-app purchase to restore? and why does it restore the purchases even though the test account hadnt bought any?

if you have any answers, can you please provide an example. Thank you

The way to handle restoreCompletedTransactions is to receive a message to the method updatedTransactions. That comes with a state "restored" rather than a state "purchased". The product information is all contained in the transaction that is delivered to that method.


The paymentQueueRestoreCompletedTransactionsFinished should not be used to fulfill purchases. It is used to tell the user that the restore process has completed. Actually - it should just detect whether or not a product was already restored through updatedTransactions and, if not, tell the user that nothing was restored.

Restoring multiple purchases
 
 
Q