Khoury
Khoury

Reputation: 431

Is it necessary to have restore code paymentQueueRestoreCompletedTransactionsFinished()?

I want to properly implement the ability to restore previously purchased IAP, but, I've read a few conflicting methods and now I'm confused.

The way I have done it, which works in sandbox, is to restore from paymentQueue(), like this..

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

case .restored:

            defer {
                queue.finishTransaction(transaction)
            }

            if let productIdentifier = transaction.original?.payment.productIdentifier {
                unlockProduct(withIdentifier: productIdentifier)
            }
}

And I just have an alert in paymentQueueRestoreCompletedTransactionsFinished(). Some other methods have restore code there, but I don't think they should.

Am I doing this right, is how I have done it the proper method, one that will work outside the sandbox environment?

Thanks.

Upvotes: 0

Views: 298

Answers (1)

Paulw11
Paulw11

Reputation: 114992

You are not required to implement paymentQueueRestoreCompletedTransactionsFinished. As you note, this is not the place to actually restore completed transactions.

What I do suggest you consider is providing appropriate user feedback when they tap the "Restore" button; Restoring transactions can take some time, so you might want to consider showing an activity spinner or other UI element to indicate that restoration is taking place. paymentQueueRestoreCompletedTransactionsFinished is where you should remove this UI.

You can also keep track of whether any purchases were actually restored and then display an appropriate message in this function. e.g. "No purchases were found" or "3 purchases have been restored"

Upvotes: 2

Related Questions