快速恢复购买

时间:2016-01-21 21:58:54

标签: ios swift in-app-purchase storekit

因此,我似乎无法在尝试恢复购买时触发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
        }
    }

}

2 个答案:

答案 0 :(得分:2)

您的控制器是否使用SKPaymentQueue.defaultQueue().addTransactionObserver(..)作为观察者添加了?

PS:看看SwiftyStoreKitInAppProductPurchaseRequest.swift

答案 1 :(得分:0)

从您的描述和代码片段看,所有内容都是正确的顺序。

如果永远不会调用IAPViewController函数,那么SKPaymentTransactionObserver可能不符合class IAPViewController: UIViewController, SKPaymentTransactionObserver协议,只需使其符合:

foreach (ServiceDescriptor service in Kendo.Mvc.KendoServices.GetServices()) services.Add(service); services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();

你很高兴。