I am using in-app purchase for an iPhone app. I have a class that acts as SKProductsRequestDelegate and SKPaymentTransactionObserver, and it\'s all
It's possibly caused by multiple observers. Don't think you're safe by just removing observer in dealloc.
You called [[SKPaymentQueue defaultQueue] addTransactionObserver:self] in viewDidLoad and [[SKPaymentQueue defaultQueue] removeTransactionObserver:self] in dealloc. You think you're safe like I did but you're not.
Actually, if you purchase something, finish transaction, remove it from payment queue, pop out this view controller from navigation view controller, then you enter the view controller again, you're probably have multiple transaction observers.
Every time you push this view controller you're adding the view controller itself as transactionObserver but every time you pop this view controller doesn't guarantee that you're removing the view controller itself from transactionObservers.
Somehow a view controller's dealloc not get called even if you pop the view controller. So the view controller is still observing in the dark.
I think the best solution for this situation is detecting if this view controller is visible when you process the transaction.
Simply add this before you process the transaction, it works for me:
if ( !self.view.window) {
return;
}
visible detection is referenced from here.
ps. Maybe put/remove transactionObserver in viewWillAppear/viewWillDisappear is another way to solve that, but you have to carefully handle the keyboard show/hide events in case the user needs type password.