I have a class that implements SKPaymentTransactionObserver
. However when clicking a buy button, if the user is not signed into the app store they get an alert asking for an existing ID or to create a new one. If the use clicks cancel from this, or a subsequent login credentials alert, I receive no notification of that cancellation. I have an activity view covering the screen after the buy button is clicked so I really need to know if the login alert was cancelled.
I already test for the error code SKErrorPaymentCancelled
and that works if the purchase process is cancelled after logging in. I'm testing on a device.
Any clues?
-UPDATE-
Apologies I forgot to mention that this only happened when attempting to restore transactions, and that reveals the answer: my lack of knowledge about the protocol.
On the Google Play Store app, in-app purchases will be by the Price or Install button. On play.google.com/store, you'll see "Offers in-app purchases" below the name of the app.
To detect the cancel event after a user tries to cancel a restore purchases request implement:
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
// test error.code, if it equals SKErrorPaymentCancelled it's been cancelled
}
In Swift 3.0
public func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
print("Cancel Transaction");
}
In Swift 2.2
public func paymentQueue(queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: NSError) {
print("Cancel Transaction")
}
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