我无法在 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
状态。.purchased
paymentQueue
但是,当我为此调用以下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
}
}
}