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

in-app-purchase, iphone, objective-c, storekit, xcode

Solution

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];
    }
}

Problem

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?

Original source