latest(for:)
Gets the customer’s most recent transaction for an In-App Purchase.
Declaration
static func latest(for productID: String) async -> VerificationResult<Transaction>?Parameters
- productID:
The product identifier that the method uses to look up the most recent transaction.
Return Value
A VerificationResult with a single Transaction, or nil if the customer hasn’t purchased the product.
Discussion
Call this method for any type of In-App Purchase. The following code example illustrates requesting the most recent transaction to determine whether the customer purchased the product indicated by the string productIdentifier:
guard let verificationResult = await Transaction.latest(for: productIdentifier) else {
// The customer hasn't purchased this product.
return
}
switch verificationResult {
case .verified(let transaction):
// Check the transaction and give the customer access to purchased
// content as appropriate.
...
case .unverified(let transaction, let verificationError):
// Handle unverified transactions based
// on your business model.
...
}By default, when the SKIncludeConsumableInAppPurchaseHistory property list key is false, this method excludes finished consumable in-app purchases unless they are refunded or revoked.
If you set the SKIncludeConsumableInAppPurchaseHistory property list key to true, this method returns all transactions, including consumable In-App Purchases that your app marked as finished (finish()).