In App Purchase Crashes on [[SKPaymentQueue defaultQueue] addPayment:payment]

The error message indicates a message is being sent to a deallocated instance of InAppPurchaseManager, which is your class. And it’s happening after you open the view (creating an instance), close the view (releasing an instance), then opening the view again (creating a second instance). And the problem is happening within the addPayment: call. This indicates that the framework still has a handle on your old, released instance, and is trying to send it a message.

You give the framework a handle to your object in loadStore, when you call

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

I don’t see anywhere where you remove self as an observer. Objects that send out notifications usually do not retain their observers, since doing so can create a retain cycle and/or a memory leak.

In your dealloc code you need to cleanup and call removeTransactionObserver:. That should solve your problem.

Leave a Comment