Chewie The Chorkie
Chewie The Chorkie

Reputation: 5264

Swift: Detect when buy alert displays for in-app purchases

I have code similar to a tutorial for in-app purchases shown here: https://www.raywenderlich.com/122144/in-app-purchase-tutorial

Edit: This would not only need to work for the Buy alert, but also the alert window that comes up if the user needs to put in their Username and password.

Since it takes some time for the Buy alert to show up, I put a "please wait" screen up and disabled my buttons. The problem is that I don't know how to detect the Buy alert, or where in this code it's called to show up so that I can remove the "please wait" screen at the correct time.

For instance, I call purchaseMyProduct, but I see nothing inside that function that makes that popup display, or nothing called at the same time the popup displays. My only guess is that it adds to the SKPaymentQueue, and then it's up to the OS to show the Buy popup whenever it's ready to display.

Upvotes: 1

Views: 969

Answers (1)

matt
matt

Reputation: 536027

Don't put up a "please wait" screen. The interchange with the app store happens outside your process. You can't detect it, and you don't need to. When the user taps your Buy button, just dismiss your Buy interface, stick your product onto the queue, and have your app go back to a normal quiescent state. The next voice you'll hear, if any, will be your SKPaymentTransactionObserver telling you that the user did in fact make the purchase.

Upvotes: 1

Related Questions