One Logo Pool Ball
_StoreKit_SwiftUI · IOS API REFERENCE

PurchaseAction

struct · iOS 17.0+ · SDK 27.1

@MainActor @preconcurrency struct PurchaseAction

An action that starts an in-app purchase. Read this environment value to get an ``PurchaseAction`` instance for a given ``Environment``. Call the instance to start an in-app purchase. You call the instance directly because it defines a ``PurchaseAction/callAsFunction(_:options:)`` method that Swift calls when you call the instance. For example, you can start an in-app purchase when the user taps a button: struct PurchaseExample: View { @Environment(\.purchase) private var purchase let product: Product let purchaseOptions: [Product.PurchaseOption] var body: some View { Button { Task { let purchaseResult = try? await purchase(product, options: purchaseOptions) // Process purchase result. } } label: { Text(product.displayName) } } }

Members (2)

method · iOS 18.4+

callAsFunction

TypeScript
callAsFunctionCompactJWSOptions(advancedCommerceProduct: _StoreKit_AdvancedCommerceProduct, compactJWS: string, options?: Array<_StoreKit_AdvancedCommerceProduct_PurchaseOption>): Promise<_StoreKit_Product_PurchaseResult>
Swift declaration
@MainActor @preconcurrency func callAsFunction(_ advancedCommerceProduct: AdvancedCommerceProduct, compactJWS: String, options: Set<AdvancedCommerceProduct.PurchaseOption> = []) async throws -> AdvancedCommerceProduct.PurchaseResult
method · iOS 17.0+

callAsFunction

TypeScript
callAsFunctionOptions(product: _StoreKit_Product, options?: Array<_StoreKit_Product_PurchaseOption>): Promise<_StoreKit_Product_PurchaseResult>
Swift declaration
@MainActor @preconcurrency func callAsFunction(_ product: Product, options: Set<Product.PurchaseOption> = []) async throws -> Product.PurchaseResult

Starts an in-app purchase for the given product, with the given purchase options. Don't call this method directly. SwiftUI calls it when you call the ``PurchaseAction`` structure that you get from the ``Environment``, using the product and purchase options as arguments: struct PurchaseExample: View { @Environment(\.purchase) private var purchase let product: Product let purchaseOptions: [Product.PurchaseOption] var body: some View { Button { Task { let purchaseResult = try? await purchase(product, options: purchaseOptions) // Process purchase result. } } label: { Text(product.displayName) } } } - Parameters: - product: The product to purchase. - options: A set of options to configure the purchase. - Returns: The result of the purchase - Throws: A `PurchaseError` or `StoreKitError`.

Skipped declarations

No declarations were skipped in this snapshot.

All _StoreKit_SwiftUI types →