4

我无法在 Swift 4/iOS 11 中恢复 IAP。我的AppDelegate工具SKPaymentTransactionObserver. AppDelegate我正在didFinishLaunchingWithOptions打电话SKPaymentQueue.default().add(self)。我paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])也在 AppDelegate 中实现了这个功能。

ViewController我可以像这样购买:

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

购买成功完成 - 我在我的观察者中获得了一个updatedTransaction状态。.purchasedpaymentQueue

但是,当我为此调用以下ViewController命令以恢复购买时:

SKPaymentQueue.default().restoreCompletedTransactions()

paymentQueue updatedTransactions函数永远不会被调用。

似乎我的沙盒用户等设置正确,因为初始购买有效。沙盒用户是否有能力恢复购买?restoreCompletedTransactions()除了打电话恢复购买外,我还需要做任何额外的工作吗?


更新,这是我的paymentQueue updatedTransactions代码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
        }
    }
}
4

0 回答 0