Why are there unexpected transactions coming through the delegate method even after finishing the transaction?
The following is how I handle IAP transactions. I've read through multiple similar questions, but I couldn't fix it still and I don't fully understand why this is happening.
-
First, I finish all
purchased,restoredandfailedtransactions on init of my IAP manager. Therefore, this leaves me with 0 transactions. -
I add
selfas observer on init (right after step 1), like so:SKPaymentQueue.default().add(self) -
I add the payment to queue. This is triggered by user interaction.
-
Wait for callback on the following delegate method.
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
switch transaction.transactionState {
case .purchased:
// This basically just persists the successful purchase somewhere. Once it's done, it returns a callback.
saveTransaction(transaction.transactionIdentifier) {
queue.finishTransaction(transaction)
}
case .failed, .restored:
queue.finishTransaction(transaction)
case .purchasing, .deferred:
break
@unknown default:
queue.finishTransaction(transaction)
}
}
The weird thing happens here. Even if I started with 0 transactions (step 1) and even after finishing the transactions for purchased, restored and failed states on updatedTransactions delegate (step 4), LOTS MORE of unknown transactions will come through updatedTransactions with the purchased status.
Even if I don't call saveTransaction and just directly finish transaction, I still receive all those unexpected transactions.
Where did those transactions even come from??