Cancel Detection Button Click Confirm In-App Purchase UIAlert

I implemented an in-app purchase based on this tutorial. The problem I am experiencing is that I cannot detect when the Cancel button is clicked in the Confirm In-App Purchase alert, which is part of the StoreKit structure.

Some sources suggest that it -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactionsis called when Cancel is clicked, but in my case it never starts. My setup is a ViewController that imports the IAPManager: NSObject class, which corresponds to SKProductRequestDelegate and SKPaymentTransactionObserver. The product is successfully requested, but the transaction observer never calls paymentQueue.

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

+5
source share
3 answers

in the delegate method, I look at the failtransaction tutorial does nothing if the user cancels. but you can add it like this.

- (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];
    }
}
+10
source

This line should have been added to make it work:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

Thank you all for your help.

+1
source

StoreKit, , SKRequestDelegate request:didFailWithError:, .

0
source

All Articles