我在购买完成时进行SKPaymentTransactionObserver
检查
extension IAPService: SKPaymentTransactionObserver {
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
print(transaction.transactionState.status(), transaction.payment.productIdentifier)
if transaction.transactionState.status() == "purchased" {
// Pro Purchased
}
switch transaction.transactionState {
case .purchasing: break
default: queue.finishTransaction(transaction)
}
}
}
}
如何在购买完成时购买的ViewController
上隐藏对象
答案 0 :(得分:3)
您可以在IAPService类中创建一个闭包:
var productDidPurchased: (() -> Void)?
然后在您的扩展程序中,您可以这样使用它:
switch transaction.transactionState {
case .purchasing:
break
case .purchased:
productDidPurchased?()
default:
queue.finishTransaction(transaction)
}
然后在你的ViewController中检索它:
IAPService.shared.productDidPurchased = {
[weak self] in
//you will receive a callback when the product is purchased and can hide your view here
}