Reputation: 3740
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?
Upvotes: 7
Views: 4210
Reputation: 3740
This line had to be added to make it work:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
Thanks all for your help.
Upvotes: 1
Reputation: 1885
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];
}
}
Upvotes: 13
Reputation: 16089
I haven't used StoreKit, but I'm guessing that your SKRequestDelegate
will receive the message request:didFailWithError:
if the user cancels.
Upvotes: 0