Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring purchases in swift

So i can't seem to get the updatedTransactions protocol to fire when trying to restore purchases.

I have a button in one view controller which calls the following method in my IAPViewController file restoreIAP() which is set up like so.

func restoreIAP(){

    SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}

This method is called when the user presses the button so this is the class which handles this.

class SettingsViewController: IAPViewController {


    @IBAction func restoreDidTouch(sender: AnyObject) {

        restoreIAP()
        activityTitle = "Restoring"

    }

}

In my IAPViewController nothing seems to be triggering 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
        }
    }

}
like image 214
Tunds Avatar asked Oct 31 '22 11:10

Tunds


1 Answers

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

PS: Have a look at SwiftyStoreKit ( InAppProductPurchaseRequest.swift )

like image 76
phimage Avatar answered Nov 15 '22 06:11

phimage