paymentqueue crash

I'm developing two in app purchases using Sandbox testing. It works fine "buying" but not always "restoring." I think I have tracked the problem down to the finishtransaction method call. The restore purchases for the first product works ok, but when I try to restore the purchase of the second product I get a crash on a background thread immediately after a breakpoint on the finishtransaction call. This happens every time when I repeat this sequence. I can see my paymentqueue observer being called sequentially for the two transactions as should occur when I restore purchases. However, when the transaction state is "restored" and I release the breakpoint at finishtransaction I get this crash. Has anyone had this problem? Is it only a problem in Sandbox testing or will it also happen during app review? BTW, no crash shows up in the device crash log. iPhone 6, iOS 9.3, iPad mini retina, iOS 9.3. Happens either running from Xcode or after installing on the device.

One idea - you don't want to call finishTransaction on a state of 'SKPaymentTransactionStatePurchasing'.

Other than that, check your code to be sure you still have a good reference to transaction in the finishTransaction

I fixed the problem by adding an "optional" method (per Apple's Best Practices) in my in app purchases controller:


-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue{

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

}


I had a bug in which I added self as a transaction observer when doing the restore purchase transaction:


- (IBAction)restoreCompletedTransactions:(id)sender

{

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

}


The crash apparently happened because I never removed self. The "optional" method fixed the bug.

Glad your bug is 'gone' but what you described would not actually eliminate the bug. It is possible that you are deallocating 'self' (you didn't post that possibility) while leaving a transaction observier attached to self - and getting another transaction - the bug is .....'why are you getting another transaction???' By removing the transaction observer you are leaving a transaction hanging - not a good thing to do and another 'bug' that isn't causing a crash, yet.

paymentqueue crash
 
 
Q