I'm using StoreKit for in-app purchases. I'm finding that the API is quirky in its behavior when the user presses the "Cancel" button.
For example, if I push Cancel on the "Confirm Your In App Purchase" screen, I get a SKPaymentTransactionStateFailed
transaction with error.code == SKErrorPaymentCancelled
as I'd expect.
But if I push Buy and then press Cancel, I get a Failed
transaction with error.code == 0
. The error.localizedDescription
is "Cannot connect to iTunes Store" which is clearly a lie.
It's tempting to treat all Failed
transactions as ignorable cancellations, but I can also clearly see that if the device is offline in airplane mode, I get a Failed
transaction with no alert popup; I should really notify the user to explain the problem in that case.
I note that MKStoreKit assumes all failures are cancellations. MKStoreManager
's failedTransaction
method is never called; MKStoreObserver
always calls transactionCanceled
for all Failed
transactions. The MKStoreManager.h
comments recommend no error message for transactionCanceled
, which makes sense, but then who will notify the user about Failed
non-cancelled transactions?
What's the best practice for handling these failures? Should I swallow errors? Always show an error, even if it's redundant?
To restore your purchases:Open the drawer from the upper left corner of the screen and select Support. Select Purchases and Paid App from the menu. Tap on the menu option, located in the upper right-hand corner of the screen. Tap on Recover Paid App.
They automatically renew at the end of their duration until the user chooses to cancel. Subscriptions are available on iOS, iPadOS, macOS, watchOS, and tvOS.
We have a pretty substantial user base buying stuff over mobile connections and only show alerts for
code != SKErrorPaymentCancelled && code != SKErrorPaymentNotAllowed
Apparently, it's the best you can do. I've also seen the weird behavior on cancellation that you mention, which is a framework bug as far as I can tell.
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