restoreCompletedTransactions() not calling paymentQueue updatedTransactions?

随声附和 提交于 2019-12-13 14:08:19

问题


I am having trouble restoring an IAP in Swift 4/iOS 11. My AppDelegate implements SKPaymentTransactionObserver. In AppDelegate's didFinishLaunchingWithOptions I'm calling SKPaymentQueue.default().add(self). I implement the paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) function in AppDelegate as well.

From a ViewController I can make a purchase like so:

let payment = SKPayment(product: products.first!)
SKPaymentQueue.default().add(payment)

The purchase finishes successfully - I get an updatedTransaction with state .purchased in my paymentQueue observer.

However, when I call the following from this same ViewController in order to restore the purchase:

SKPaymentQueue.default().restoreCompletedTransactions()

the paymentQueue updatedTransactions function is never called.

It seems like my sandbox user, etc. is set up correctly since the initial purchase is working. Do sandbox users have the ability to restore purchases? Do I need to do any additional work besides calling restoreCompletedTransactions() to restore purchases?


Update, here is my paymentQueue updatedTransactions code that lives in AppDelegate:

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction in transactions{
        switch transaction.transactionState{
        case .purchased:
            debugPrint("purchased it!")
            menuDelegate?.unlockMenu()
            //unlock the content, then
            SKPaymentQueue.default().finishTransaction(transaction)
            break
        case .failed:
            debugPrint("failed")
            SKPaymentQueue.default().finishTransaction(transaction)
            break
        case .restored:
            debugPrint("restored")
            menuDelegate?.unlockMenu()
            //unlock the content, then
            SKPaymentQueue.default().finishTransaction(transaction)
            break
        case .purchasing:
            debugPrint("purchasing...")
            break
        case .deferred:
            debugPrint("deferred...")
            break
        }
    }
}

来源:https://stackoverflow.com/questions/48697258/restorecompletedtransactions-not-calling-paymentqueue-updatedtransactions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!