Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXC_BAD_ACCESS on payment section of in app purchases

I have a UITableView set up with different in app purchases. Each option takes you to a view controller which also has the delegate and what not to do the in app purchases. A plist file is change to determine which option in the table view was selected. This all works fine. I put in NSLogs to make sure the variable was getting set. However when i click buy, it only works half the time and the other half i get

EXC_BAD_ACCESS

on the line:

[[SKPaymentQueue defaultQueue] addPayment:payment];

Everything is set up right as far as the in app purchases go because it used to work before i switched to this way of doing it. I think it may have something to do with calling the productsRequest because i set up NSLog in the didReceiveResponse delegate and it receive the response much quicker after the first time. Im stuck. The ones that dont work are always random, no rhyme or reason. Any help is appreciated.

like image 759
Barry Nailor Avatar asked Aug 27 '11 01:08

Barry Nailor


1 Answers

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)
}
like image 59
benvolioT Avatar answered Oct 20 '22 01:10

benvolioT