Recover InApp Purchase with Fast, iOS

I am performing a recovery when I purchase an application. I have a button whose action

@IBAction func restorePurchases(send : AnyObject){ SKPaymentQueue.defaultQueue().restoreCompletedTransactions() // if (success) { // I want to do something here // } } 

My question is.

  • Is this correct to restore?
  • How can we confirm the success of action to restore purchases?
+5
source share
1 answer

do not forget to check if you can make a payment:

 if (SKPaymentQueue.canMakePayments()) { SKPaymentQueue.default().restoreCompletedTransactions() } 

To verify the recovery, you must follow the protocol: SKPaymentTransactionObserver and then implement the method:

 func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) 

and subscribe to the event by doing:

 SKPaymentQueue.default().add(self) 

Finally, here is an example of how I check the result:

 func paymentQueue(_ queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) { print("Received Payment Transaction Response from Apple"); for transaction in transactions { switch transaction.transactionState { case .purchased, .restored: print("Purchased purchase/restored") SKPaymentQueue.default().finishTransaction(transaction as SKPaymentTransaction) break case .failed: print("Purchased Failed") SKPaymentQueue.default().finishTransaction(transaction as SKPaymentTransaction) break default: print("default") break } } } 
+23
source

Source: https://habr.com/ru/post/1214213/


All Articles