Guides
Your own paywall
Keep drawing your own paywall and let Horse do the rest: read the offering's packages, buy them, restore, and tell Horse when the paywall shows so conversion is still counted.
#Read the offering
let offerings = try await Horse.shared.offerings() // cached for 5 minutes
let offering = offerings.current // the one marked current
let onboarding = offerings.currentOffering(forPlacement: "onboarding") // falls back to current
for package in offering?.availablePackages ?? [] {
package.identifier // "$rc_annual"
package.storeProduct // the StoreKit 2 Product: displayPrice, subscription, …
}
offering?.annual; offering?.monthly; offering?.weekly; offering?.lifetime
// Custom fields (Offerings → Custom fields)
offering?.string("headline", default: "Go Pro")
offering?.bool("show_close_button", default: true)Read the placement's offering rather than hard-coding one. Targeting and experiments can change it per person, and your code follows.
#Buy
do {
let result = try await Horse.shared.purchase(package: package)
if result.userCancelled { return }
unlock(result.customerInfo.isEntitled("pro"))
} catch HorseError.purchasePending {
// Ask to Buy, or a payment that needs approval: access arrives later, through customerInfoStream
} catch let error as HorseError where error.isCancellation {
} catch {
show(error)
}For a promotional offer, build the StoreKit purchase option yourself and call purchase(product:options:).
#Report the paywall
Designed paywalls do this themselves. With your own, tell Horse when it shows and closes, and conversion is counted per paywall and placement:
MyPaywall()
.onAppear { Horse.shared.paywallShown(offering: offering, placement: "onboarding") }
.onDisappear { Horse.shared.paywallClosed(offering: offering, placement: "onboarding") }
// When a plan is tapped:
Horse.shared.paywallPlanSelected(package: package, placement: "onboarding")purchase(package:) credits the purchase to the package's offering, with the placement you gave paywallShown. None of these calls throws or waits: the events go out together a moment later.
#Restoring
| Call | What it does | Where |
|---|---|---|
restorePurchases() | Asks the App Store to sync, then claims everything the Apple Account owns | Only behind a Restore button, because it can show Apple's sign-in prompt |
syncPurchases() | Claims what StoreKit already knows about on the device, silently | After logIn, or on update day after a migration |
With the default restorePolicy: .onRestore, a fresh install doesn't unlock by itself even when the Apple Account owns a subscription. The person taps Restore. That keeps reinstalls honest and lets testers see the paywall again. Set restorePolicy: .automatic to claim at launch instead. Purchases made in this install, and their renewals, are always recognised at once with either setting.
#Products outside offerings
let products = try await Horse.shared.products(["lumi.credits.100"])
let result = try await Horse.shared.purchase(product: products[0])A purchase made with purchase(product:) is credited to the paywall last reported with paywallShown in the previous 30 minutes.