因此,当我尝试恢复购买时,似乎无法启动updatedTransactions协议(protocol)。

我在一个 View Controller 中有一个按钮,该按钮在我的IAPViewController文件restoreIAP()中调用以下方法,该方法是这样设置的。

func restoreIAP(){

    SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}

用户按下按钮时将调用此方法,因此这是处理此问题的类。
class SettingsViewController: IAPViewController {


    @IBAction func restoreDidTouch(sender: AnyObject) {

        restoreIAP()
        activityTitle = "Restoring"

    }

}

在我的IAPViewController中,似乎什么都没有触发此方法,所以我可以做点什么。
// 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
        }
    }

}

最佳答案

您的 Controller 是否使用SKPaymentQueue.defaultQueue().addTransactionObserver(..)添加为观察者?

PS:看看SwiftyStoreKit(InAppProductPurchaseRequest.swift)

09-27 10:25