horse revenue Docs

Guides

Paywalls

Design a paywall per offering on the Paywalls tab, and HorseKitUI draws it natively in SwiftUI, with the person's language, currency, intro offers and Dynamic Type. Words, plans, colours and layout change without a release.

The tutorial covers making a first design. This page covers everything after that.

#Showing it

import HorseKit
import HorseKitUI

// When the entitlement is missing (it waits for the customer's access first):
ContentView()
    .presentPaywallIfNeeded(requiredEntitlement: "pro", placement: "onboarding")

// When you decide:
ContentView()
    .presentPaywall(isPresented: $showPaywall, placement: "settings")

// As a view, with your old paywall as the fallback:
PaywallView(placement: "onboarding") {
    LegacyPaywall()
}
InitialiserShows
PaywallView()The current offering's paywall
PaywallView(placement:)The offering that the placement sells
PaywallView(offering:)A given offering's paywall
PaywallView(offeringIdentifier:)An offering by id. An empty id means the placement's offering, so an app's own "which offering" setting can go straight in.

#What it does on its own

  • Loads the design in the device's language, from a disk cache when the version hasn't changed (so it opens at once), and the last copy when offline. It downloads images and videos ahead of time.
  • Fills in prices and trial wording from StoreKit in the person's currency, and checks whether the person can still take the intro offer before promising a trial.
  • Buys, restores, opens Terms and Privacy, and opens the App Store's sheets for redeeming offer codes and managing subscriptions.
  • Reports when it's shown, which plan is selected and when it's closed, so conversion per paywall needs no app code.
  • Respects Reduce Motion, and puts a grown-up check in front of buying when the design asks for one (for kids' apps).

#Reacting to purchases

PaywallView(placement: "onboarding")
    .onPurchaseCompleted { (purchase: PaywallPurchase) in
        // purchase.packageId, purchase.placement, purchase.product.id
        // purchase.startedFreeTrial, .startedIntroOffer, .startedWinBackOffer
    }
    .onRestoreCompleted { info in … }
    .onPurchaseFailed { error in … }     // cancelling isn't a failure
    .onPaywallDismiss { … }              // closed, or done after a purchase
    .onPlanSelected { packageId in haptics.tick() }

Name the type in onPurchaseCompleted's closure to get the PaywallPurchase. Leave it out to get just the CustomerInfo.

#Variables

Texts can hold variables, filled in for each plan from the App Store:

VariableExample
{{price}}$39.99
{{price_per_week}}$0.77
{{period}}year
{{trial_length}}3 days
{{trial_days}}3
{{savings}}80%
{{original_price_per_week}}$6.99

Use Insert a variable in the designer to see them all. A plan's texts can differ when it has a free trial or an intro price. Preview both with Pretend a 3-day trial.

#The selected plan

Blocks can follow the plan the person has selected. The button can say Start free trial for a plan with a trial and Continue for one without, and a block can appear only when the selected plan has a trial (or a win-back offer). Set this under the block's Behaviour · selected plan.

#Your own views

A Custom view block names a component, and your app draws it with the properties set in the dashboard. Register it anywhere above the paywall, once at the root for every paywall in the app:

PaywallView(placement: "onboarding")
    .paywallComponent("mascot") { props in
        MascotView(mood: props["mood"]?.stringValue ?? "happy")
    }

A component that isn't registered leaves its space empty. A custom background works the same way.

#Your colours

.paywallColors replaces the design's theme colours by name, for an app whose look follows a setting:

PaywallView(placement: "onboarding")
    .paywallColors(["accent": theme.accent, "background": theme.background])
    .paywallFollowsDeviceAppearance()   // when those colours change with light and dark

The names are background, text, secondaryText, accent, onAccent, surface, border, selected, badge, onBadge and tint. Names you leave out keep the design's colours. A custom font named in the design has to be bundled with the app.

#Win-back offers

Apple's win-back offers (iOS 18) bring back someone who cancelled, with a lower price or some time free. App Store Connect decides who can take one. An offer that App Store Connect doesn't promote reaches nobody unless your app sells it.

  1. Switch it on

    Under the design's Behaviour, turn on selling win-back offers.

  2. Write the texts

    Give the plans and the button their with a win-back offer texts, using {{winback_price}}, {{winback_length}}, {{winback_period}} and {{winback_price_per_week}}.

  3. Preview it

    Use Pretend a win-back offer, or preview as a Lapsed subscriber.

The paywall asks StoreKit which offer this Apple Account can redeem on each plan, and buys with it. Everyone else sees and pays the plain price. Drawing your own paywall:

if let offer = await Horse.shared.eligibleWinBackOffer(for: weekly) {
    try await Horse.shared.purchase(package: weekly, winBackOffer: offer)
}

#Before you publish

  • Checks in the designer flag what App Review objects to, such as no Restore button, no Terms, or a weekly price louder than what's billed. Publish only once the list is empty.
  • PaywallView(placement: "onboarding", draft: true) shows the unpublished draft on a device. Put it in a debug menu, never in a release build.
  • PaywallView(design:packages:) draws a design with made-up products and buys nothing, for SwiftUI previews:
PaywallView(design: design, packages: [
    PaywallPackage(id: "$rc_annual", product: .init(id: "pro.year", price: 39.99, period: .init(.year), displayName: "Yearly")),
    PaywallPackage(id: "$rc_weekly", product: .init(id: "pro.week", price: 6.99, period: .init(.week),
                                                    intro: .init(kind: .freeTrial, period: .init(.day, 3)), displayName: "Weekly")),
])

#No design, or an old app

  • With no published design, PaywallView shows your fallback, or a short message with Retry and Close. offering.hasPaywall tells you beforehand.
  • A block type that an older SDK doesn't know is skipped, and the rest of the paywall still shows. A design that needs a newer SDK than the app has shows the fallback.