Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if user cancelled SKPaymentTransaction

How can I check if user tapped cancel button (either when he was asked if he wants to purchase smth or perhaps if he already purchased this SKProduct whether he wants to download it)?

For now I just receive SKPaymentTransactionStateFailed in paymentQueue:updatedTransactions: method both after user taps cancel button and for instance when there is no internet. Any way to differentiate these two cases?

like image 950
dariaa Avatar asked Nov 26 '12 18:11

dariaa


2 Answers

This code works for me:

if (transaction.error.code != SKErrorPaymentCancelled) {
    NSLog(@"Other error");
} else {
    NSLog(@"User canceled");
}
like image 168
Ellen S Avatar answered Sep 29 '22 07:09

Ellen S


Ellen's answer is perfect. Just in case someone is wondering about the other cases

switch (transaction.error.code) {
   case SKErrorUnknown:
       //Unknown error
       break;
   case SKErrorClientInvalid:
       // client is not allowed to issue the request, etc.
       break;
   case SKErrorPaymentCancelled:
       // user cancelled the request, etc.
       break;
   case SKErrorPaymentInvalid:
       // purchase identifier was invalid, etc.
       break;
   case SKErrorPaymentNotAllowed:
       // this device is not allowed to make the payment
       break;
   default:
       break;
}
like image 33
Oscar Avatar answered Sep 29 '22 08:09

Oscar