Skip to main content

Purpose

Create and present Encore offers using a fluent API that fits naturally in SwiftUI and UIKit. Purchase handling and passthrough logic are managed by app-level handlers — see onPurchaseRequest().

Signature

public static func placement(_ id: String? = nil) -> Placement

public struct Placement {
  public func show()
  public func show() async throws -> EncorePresentationResult
}

Methods

MethodParametersDescription
placement()id: String?Creates a placement with optional identifier. If omitted, auto-generates unique ID
show()NonePresents the offer sheet modally
show() asyncNonePresents the offer and returns EncorePresentationResult or throws EncoreError

Returns / State

placement() returns a Placement instance. Call show() to present. Purchase outcomes are delegated to your onPurchaseRequest() and onPassthrough() handlers.

Usage Patterns

Cancellation Flow

Button("Cancel Subscription") {
    Encore.placement("cancellation_flow").show()
}
Provide a placement ID to identify this specific placement in analytics and your passthrough handler.

Async/Await Pattern

Button("Cancel Subscription") {
    Task {
        do {
            let result = try await Encore.placement("cancellation_flow").show()
            switch result {
            case .granted(let entitlement):
                print("User accepted: \(entitlement)")
            case .notGranted(let reason):
                print("Not granted: \(reason)")
            }
        } catch {
            handleError(error as? EncoreError ?? .unknown)
        }
    }
}

Passive Offer (No Callbacks)

Button("See Offer") {
    // Just show the offer - entitlement state managed automatically via isActivePublisher
    Encore.placement("upsell_modal").show()
}
When you don’t need custom flow control, you can present with no callbacks. The SDK automatically manages entitlement state through isActivePublisher(). Purchases are handled by your registered onPurchaseRequest() handler.