Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 343
Spiri Avatar asked Oct 26 '25 09:10

Spiri


1 Answers

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.

like image 171
Spiri Avatar answered Oct 28 '25 00:10

Spiri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!