dariaa dariaa - 10 months ago 145
iOS Question

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?

Answer Source

Check the SKPaymentTransaction error property that is set. Additionally, you may want to use Apple's Reachability class to determine if Internet is available prior to initiating the transaction.

error An object describing the error that occurred while processing the transaction. (read-only)

@property(nonatomic, readonly) NSError *error Discussion The error property is undefined except when transactionState is set to SKPaymentTransactionStateFailed. Your application can read the error property to determine why the transaction failed.

Availability Available in iOS 3.0 and later. Declared In SKPaymentTransaction.h