Tutorial: your first app
Show the paywall
The paywall buys, restores, opens your Terms and Privacy Policy, checks whether a free trial can be offered, and closes itself after a purchase. Your app only decides when to show it.
#When the person isn't entitled
The simplest case is a paywall that appears whenever the entitlement is missing, for example during onboarding:
import HorseKit
import HorseKitUI
ContentView()
.presentPaywallIfNeeded(requiredEntitlement: "pro", placement: "onboarding")It waits until the customer's access is known, so someone who already pays never sees it flash.
#When you decide
Behind a locked feature or a button in Settings:
@State private var showPaywall = false
SettingsView()
.presentPaywall(isPresented: $showPaywall, placement: "settings")#As a view, with a fallback
PaywallView puts the paywall wherever you want it: in a sheet, a full-screen cover or a navigation stack. Give it your old paywall as the fallback. It's shown when no design has been published yet, or on a device that has never been online:
.fullScreenCover(isPresented: $showPaywall) {
PaywallView(placement: "onboarding") {
LegacyPaywall()
}
.onPurchaseCompleted { (purchase: PaywallPurchase) in
analytics.log("purchase", product: purchase.product.id, trial: purchase.startedFreeTrial)
}
.onRestoreCompleted { info in … }
.onPurchaseFailed { error in … } // cancelling isn't a failure
.onPaywallDismiss { … }
}Inside a sheet or a cover, the paywall dismisses itself after a purchase or when the person closes it.
#Placements
The placement says where in the app the paywall opened. It decides which offering is sold there (the current one unless you set another on Offerings → Placements), and it splits conversion per placement on the Analytics tab. Use a few stable names: onboarding, settings, feature_lock.
#Your own paywall instead
If you'd rather keep drawing your own paywall, read the placement's offering and buy its packages yourself. Tell Horse when the paywall shows and closes, so conversion is still counted:
let offering = try await Horse.shared.offerings().currentOffering(forPlacement: "onboarding")
let result = try await Horse.shared.purchase(package: offering!.annual!)
if !result.userCancelled { dismiss() }Your own paywall covers it all: packages, prices, errors, restoring and the conversion calls.
#What's next
Apple has to tell Horse about renewals and refunds: set up App Store Server Notifications.