0
SKPaymentQueue.default().add(payment)

I'm starting an in-app purchase with. But I think the purchase window sometimes opens late. Is there a method, delegate method to listen for the situation where this screen opens?

I researched this but I could not reach a conclusion, does anyone know?

Omer Faruk Ozturk
  • 1,722
  • 13
  • 25
Ümit Bülbül
  • 512
  • 2
  • 15

2 Answers2

1

You can use the delegate below to handle it (ex. show/hide progress view) regarding to SKPaymentTransactionState:

// Handle transaction status after you call .add(payment).
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction:AnyObject in transactions {
        if let trans = transaction as? SKPaymentTransaction {
            switch trans.transactionState {
            case .purchased:                 
                SKPaymentQueue.default().finishTransaction(trans)
                // purchased..
            case .failed:
                SKPaymentQueue.default().finishTransaction(trans)
                // failed ..
            case .restored:
                SKPaymentQueue.default().finishTransaction(trans)
                // restored
            default:
                break
            }
        }
    }
}
Omer Faruk Ozturk
  • 1,722
  • 13
  • 25
0

I suggest using a very well made (and easy to user) library for handling in-app purchases. It is called SwiftyStoreKit. enter link description here We use it in many projects and it has nice closures while handling purchasing. You can put your UI blocking progress indicator just before calling it's methods and remove when the closure returns with a result.

Tomo Norbert
  • 770
  • 4
  • 13