EXC_BAD_ACCESS on payment section of in app purchases EXC_BAD_ACCESS on payment section of in app purchases xcode xcode

EXC_BAD_ACCESS on payment section of in app purchases


I was having this problem and found that the issue was that I was releasing the transaction observer I'd added to the default SKPaymentQueue. Apparently SKPaymentQueue does not retain its observers, probably to prevent a retain cycle.

So, specifically, I changed this code:

- (void) setupAppStoreObserver {    AppStoreObserver *appStoreObserver = [[AppStoreObserver alloc] init];       [[SKPaymentQueue defaultQueue] addTransactionObserver:appStoreObserver];    [appStoreObserver release]; // This is the problem}

To this:

- (void) setupAppStoreObserver {    AppStoreObserver *appStoreObserver = [[AppStoreObserver alloc] init];       [[SKPaymentQueue defaultQueue] addTransactionObserver:appStoreObserver];    // Note, we don't release the appStoreObserver because it is not    // actually retained by SKPaymentQueue (probably to prevent retain cycles)}


You need to remove observer:

- (void)viewDidDisappear:(BOOL)animated {    [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];}


Look up NSZombieEnabled it will make anything that gets deallocated into an object that will log a message when and who called it. This is quite useful for tracking down these types of EXC_BAD_ACCESS issues.