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
) -> SubscriptionRegisters 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
- Receive product SKU via listener
- Fetch product details using fetchProducts
- Display product information to user
- Call requestPurchase with the received SKU if user confirms
Also check getPromotedProductIOS on app launch for pending promoted products.