Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting a cancelled itunes login alert for in-app purchases

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.

like image 502
Andrew Tetlaw Avatar asked Feb 05 '13 15:02

Andrew Tetlaw


People also ask

How do I see in app purchases?

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.


3 Answers

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
}
like image 158
Andrew Tetlaw Avatar answered Oct 04 '22 19:10

Andrew Tetlaw


In Swift 3.0

public func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
        print("Cancel Transaction");
    }
like image 45
Scooter Avatar answered Oct 04 '22 19:10

Scooter


In Swift 2.2

public func paymentQueue(queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: NSError) {
    print("Cancel Transaction")

}
like image 2
Mohsin Qureshi Avatar answered Oct 04 '22 20:10

Mohsin Qureshi