Use this page with AI

Copy this into your coding assistant and add your request.

Read https://openiap.dev/docs/events/ios/promoted-product-listener-ios and https://openiap.dev/llms.txt. Follow the reading instructions, detailed reference, and linked guides relevant to my task before making changes.
Inspect my existing project and reuse its framework and conventions. Ask me for missing product decisions. Implement the requested behavior and run the applicable checks.
Show the working result, the commands and actual test results, and any remaining limitations. Keep your explanation brief.

My request: [describe what customers should be able to do]
See an example request →

iOS promotedProductListenerIOS

Fired when a user clicks on a promoted in-app purchase in the App Store.

Listener Setup

swift
func promotedProductListenerIOS(
    _ listener: @escaping (String) -> Void
) -> Subscription

Registers a listener for App Store promoted product events. OpenIAP uses PurchaseIntent.intents on iOS 16.4+ and the StoreKit 1 observer only on iOS 15–16.3, so both mechanisms never run together.

swift
import OpenIap

let subscription = OpenIapModule.shared.promotedProductListenerIOS { productId in
    Task {
        print("Promoted product tapped: \(productId)")

        do {
            let result = try await OpenIapModule.shared.fetchProducts(
                ProductRequest(skus: [productId], type: .all)
            )
            guard case let .all(items) = result,
                  let item = items?.first else { return }

            switch item {
            case let .product(product):
                guard await showPurchaseConfirmation(product) else { return }
                try await OpenIapModule.shared.requestPurchase(
                    RequestPurchaseProps(
                        request: .purchase(
                            RequestPurchasePropsByPlatforms(
                                apple: RequestPurchaseIosProps(sku: productId)
                            )
                        )
                    )
                )
            case let .productSubscription(subscription):
                guard await showPurchaseConfirmation(subscription) else { return }
                try await OpenIapModule.shared.requestPurchase(
                    RequestPurchaseProps(
                        request: .subscription(
                            RequestSubscriptionPropsByPlatforms(
                                apple: RequestSubscriptionIosProps(sku: productId)
                            )
                        )
                    )
                )
            }
        } catch {
            print("Promoted purchase failed: \(error.localizedDescription)")
        }
    }
}

// Keep the token in the owning object, then call this on teardown.
func stopListeningForPromotedProducts() {
    OpenIapModule.shared.removeListener(subscription)
}

Handling Promoted Products

  1. Receive product SKU via listener
  2. Fetch product details using fetchProducts
  3. Display product information to user
  4. Call requestPurchase with the received SKU if user confirms

Also check getPromotedProductIOS on app launch for pending promoted products.