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?
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];
    }
}
This line had to be added to make it work:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
Thanks all for your help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With