Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Cancel Button Tap for "Confirm Your In-App Purchase" UIAlert

I implemented in-app purchase based on this tutorial. The problem I experience is that I cannot detect when Cancel button is pressed on the "Confirm Your In-App Purchase" alert, which is a part of StoreKit framework.

Some sources suggest -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions is called when Cancel is pressed but in my case it never runs. My set up is the ViewController which imports IAPManager:NSObject class which conforms to SKProductRequestDelegate and SKPaymentTransactionObserver. Product is successfully being requested but transaction observer is never calling paymentQueue.

How can I make it work so I can detect Cancel button?

like image 623
Vad Avatar asked Mar 14 '13 16:03

Vad


2 Answers

in delegate method i look at the tutorial failedtransaction does nothing if user cancels. but you can add it like that.

- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        // error!
          NSLog(@"Something went Wrong!");
        [self finishTransaction:transaction wasSuccessful:NO];
          NSLog(@"transaction error :%@", transaction.error.localizedDescription);
    }
    else
    {
          NSLog(@"Cancelled");
        // this is fine, the user just cancelled
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    }
}
like image 169
meth Avatar answered Nov 11 '22 17:11

meth


This line had to be added to make it work:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

Thanks all for your help.

like image 27
Vad Avatar answered Nov 11 '22 19:11

Vad