I am trying to test Ask to Buy for consumable product.
When the transaction was approved, I can get verified transaction in Transaction.updates
, meaning the process stops at a breakpoint in Transaction.updates
. However, when I call Transaction.currentEntitlements
after that, I cannot handle transaction as consumable.
Am I missing anything?
Here is my code.
func newTransactionListenerTask() -> Task<Void, Never> {
Task(priority: .background) {
for await verificationResult in Transaction.updates {
guard
case .verified(let transaction) = verificationResult,
transaction.revocationDate == nil
else { return }
// Breakpoint stops here
await refreshPurchasedProducts()
await transaction.finish()
}
}
}
func refreshPurchasedProducts() async {
for await verificationResult in Transaction.currentEntitlements {
guard case .verified(let transaction) = verificationResult else { return }
switch transaction.productType {
case .consumable:
// This code is not called
updateConsumablePurchaseCount(productID: transaction.productID)
default:
break
}
}
}