Documentation for SKPaymentQueue
notes:
To process a payment, first attach at least one observer object to the queue.
I have two observers one in the AppDelegate
(for provisioning content), and one in a UIViewController
(for updating UI state based on payment progress).
The documentation then says:
Your observer should process the transaction and then remove it from the queue.
Does this mean I can call SKPaymentQueue.default().finishTransaction(transaction)
in both observers (the AppDelegate
and UIViewController
) like this:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch transaction.transactionState {
case .deferred:
print("deferred")
case .purchasing:
print("purchasing")
case .purchased:
SKPaymentQueue.default().finishTransaction(transaction)
case .failed:
SKPaymentQueue.default().finishTransaction(transaction)
case .restored:
SKPaymentQueue.default().finishTransaction(transaction)
}
}
}
I thought SKPaymentQueue.default().finishTransaction(transaction)
destroys the transaction event for all listeners.
After some experimentation doing something similar recently, I found that multiple SKPaymentQueue observers work - they will all get called for each transaction. However after finishTransaction() is called, no remaining observers will be called (as you guessed at in your question, and which also makes sense).
I also determined that the observers always seem to be called in the order you added them. So if you want both observers to always get every transaction, make sure that the observer you add last is the only one that ever calls finishTransaction().