ios – 快速恢复购买

所以我似乎无法在尝试恢复购买时触发updatedTransactions协议.

我在一个视图控制器中有一个按钮,它在我的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
        }
    }

}

最佳答案 您的控制器是否使用SKPaymentQueue.defaultQueue()添加为观察者.addTransactionObserver(..)?

PS:看看SwiftyStoreKit(InAppProductPurchaseRequest.swift)

点赞