Shopping recovery in fast

Therefore, I can not get the protocol to updatedTransactionswork when trying to restore purchases.

I have a button in one view controller that calls the following method in my IAPViewController file restoreIAP(), which is configured like this.

func restoreIAP(){

    SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}

This method is called when the user clicks the button, so this is the class that handles this.

class SettingsViewController: IAPViewController {


    @IBAction func restoreDidTouch(sender: AnyObject) {

        restoreIAP()
        activityTitle = "Restoring"

    }

}

In mine, IAPViewControllernothing like this runs this method so that I can do something.

// Check the transaction
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

    // Check the tranactions

    for transaction in transactions {

        switch transaction.transactionState {

        case .Purchasing:
            // TODO: Start Activity Indicator
            showPurchaseIndicator(activityTitle)
            break

        case .Purchased:
            // TODO: End the purchasing activity indicator
            dismissPurchaseIndicator()
            print("Transaction completed successfully.")
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false

            // TODO: Put method here to unlock all news sources
            storiesMethods.unlockAllStories()
            break

        case .Restored:
            // TODO: Start Activity Indicator
          //  showPurchaseIndicator(activityTitle)
            break

        case .Failed:
            dismissPurchaseIndicator()
            notificationMethods.showAlertErrorMessage(self, title: "Purchase", actionMessage: "Dismiss", message: "Unable to complete transaction please try again later.")
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false
            break

        default:
            print(transaction.transactionState.rawValue)
            break
        }
    }

}
+4
source share
2 answers

Has your controller added as an observer using SKPaymentQueue.defaultQueue().addTransactionObserver(..)?

PS: SwiftyStoreKit (InAppProductPurchaseRequest.swift)

+2

, .

paymentQueue , IAPViewController, , SKPaymentTransactionObserver, :

class IAPViewController: UIViewController, SKPaymentTransactionObserver

.

0

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


All Articles