SKPaymentTransactionStatePurchased called multiple times by error
My problem was that the observer was being duplicated every time I clicked on the button or when I changed views.
The solution is adding a flag, to see if the observer has already been added.
static bool hasAddObserver=NO;
PAYMENT METHOD{
if (!hasAddObserver) {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
hasAddObserver=YES;
}
.....
I had the same problem, I would click buy on an IAP and would receive multiple responses and purchases from Apple.
addTransactionObserver()
was being called every time I left and came back to the view via viewDidLoad()
.
I needed to un-observe it in viewWillDisappear()
:
override func viewWillDisappear() {
SKPaymentQueue.defaultQueue().removeTransactionObserver(self)
}
I could't use a flag to prevent multiple observers like in mursang's answer because I listened for transactions in other views.