I have a few in-app purchases. However, I read I need to provide a way to restore them in case that they delete my application by accident. They are nonconsumable items, like skins and textures. I was reading a tutorial on this site: https://code.tutsplus.com/tutorials/in-app-purchase-tutorial-with-swift-3-ios-sdk--cms-27595
However, their explanation of restoring transactions confused me. They did this:
@IBAction func restorePurchaseButt(_ sender: Any) {
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()
}
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
nonConsumablePurchaseMade = true
UserDefaults.standard.set(nonConsumablePurchaseMade, forKey: "nonConsumablePurchaseMade")
UIAlertView(title: "IAP Tutorial",
message: "You've successfully restored your purchase!",
delegate: nil, cancelButtonTitle: "OK").show()
}
However, they never showed me where they actually used the paymentQueueRestoreCompletedTransactionsFinished(). I understand they are using the restorePurchaseButt() to restore the purchases. However, I don't understand both of these methods.
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()
How does that snippet of code even check if the user made the purchase? I don't see any if statements. And I assumed maybe restoreCompletedTransactions() triggers paymentQueueRestoreCompletedTransactionsFinished(), but I am not sure? However, even if it does, how does paymentQueueRestoreCompletedTransactionsFinished() check if the player made those transactions or not? How does it now what in-app purchases to restore when there are multiple?