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() and onPassthrough().
Signature
placement(_:) returns a value conforming to PlacementBuilderProtocol. Build it from any thread, then call show():
Encore.shared.placement(_:) and the static Encore.placement(_:) are equivalent — the static form just forwards to the shared instance.
Methods
| Method | Parameters | Description |
|---|
placement(_:) | id: String? | Creates a placement builder with an optional identifier. If omitted, a unique ID is auto-generated. |
show() async throws | None | Presents the offer sheet and returns a PresentationResult. Throws an EncoreError on transport / SDK failure. Presentation runs on the main actor automatically. |
show() | None | Fire-and-forget variant — presents the sheet and discards the result/errors. Use the async throws form when you need the outcome. |
Usage Patterns
Cancellation Flow (fire-and-forget)
Provide a placement ID to identify this specific placement in analytics and in your onPassthrough handler.
Async/Await Pattern
show() is @MainActor-driven — presentation always happens on the main thread. From a synchronous SwiftUI Button or UIKit @IBAction, wrap the await call in a Task { }.