Objective-c – EXC_BAD_ACCESS during in app purchase test

in-app-purchaseiphoneobjective cstorekitxcode

Running a test for my in app purchase (first time doing in app purchases). I get EXC_BAD_ACCESS on the third line of this code:

    SKPayment *payment = [SKPayment paymentWithProduct:electronicProd];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];

The is under an IBAction for a button. electronicPack is declared in the header as a SKProduct. Threw some NSLogs in the productsRequest didReceiveResponse, and when the product was requested (in the viewDidLoad) and they showed it was correctly fetching the product and storing it in electronicPack. Defined electronicPack as [[request.products] objectAtIndex:0] in the didReceiveResponse page. So yea. Thats where im at, dont know what to do. Any help is appreciated.

UPDATE: FIXED accidentally left in code that was adding an extra transaction observer lol

Best Answer

I've had the same issue, my solution was to call

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

on leaving the In-App Store in my App. Maybe it will help someone in the future.

Related Topic