Search code examples
objective-ciossandboxin-app-purchase

iOS In App Purchases: only one payment added to the SKPaymentQueue but a SKPaymentTransactionObserver method is getting called multiple times


I'm testing the IAP using a test user (in the sandbox), I have a class that implements the SKPaymentTransactionObserver protocol and when the user selects a certain table view cell, I initiate the payment:

SKPayment *payment = [SKPayment paymentWithProductIdentifier:productIdentifier];
[[SKPaymentQueue defaultQueue] addPayment:payment];

This is done only once and I've checked: the code gets called once. The problem is that '- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions' is sometimes called multiple times and I can't figure out why. This doesn't always happen but it should never happen.

Has anyone encountered this behavior while sandbox testing (it would be a big problem if this would happen in a real scenario)?


Solution

  • I usually 'assign' my delegates but this time the delegate to the class that handles all the transaction processing was retained. Both the delegate (a view controller) and the in app purchases class were leaked. Because of that, every time I presented the view controller, another instance was created and another delegate set. When the transaction was being handled, there were as many instances of the in app purchases class roaming free :) as the number of times the view was presented. So, it wasn't a IAP problem - it was a problem of attention and memory management.