ios - swift 恢复购买

标签 ios swift in-app-purchase storekit

所以我似乎无法在尝试恢复购买时触发 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 )

关于ios - swift 恢复购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34935122/

相关文章:

ios - 从触摸位置快速获取 SCNNode 环境中的矢量

ios - Oauth2 facebook 回调 swift

ios - 我的自定义单元格的标签大小不会改变,即使是硬编码值也是如此。什么可以阻止这种情况?

ios - 在 iPhone 上测试 IAP

iphone - Apple 是否在任何地方发布应用程序购买系统状态?是否可以确定他们的系统是否/何时停机?

java - Play Billing Library v1.0 过期订阅

android - 选择 OpenGL ES 的适当错误

ios - 如何在 Swift 中将值附加到多级字典?

javascript - 使用 Node js 验证 Google ID token

ios - 如何禁用向后/向左滑动手势?