Show your first paywall in a SwiftUI app
To show a paywall in a SwiftUI app with BillDog, add the BillDogFull package with Swift Package Manager, call BillDog.shared.configure once at launch, then call register(placement:) where you want the paywall. The dashboard picks the paywall, StoreKit handles the purchase, and getCustomerInfo() tells you whether to unlock.
Steps last checked against the SDK source on 15 Nov 2026.
What you'll build
- A SwiftUI app that shows a paywall chosen in the dashboard
- Content that unlocks when the
premiumentitlement is active - A Restore Purchases button that App Review expects
What you'll need
- Xcode 26 or later (the binaries are built with Swift 6.3) and an iOS 15+ deployment target
- A free BillDog project (sign up)
- A subscription product in App Store Connect (App Store setup codelab)
1. Add the SDK with Swift Package Manager
3 minIn Xcode choose File → Add Package Dependencies, paste the URL below and add the BillDogFull product to your app target. In a Package.swift, add it like this:
dependencies: [
.package(url: "https://github.com/billdogai/billdog-ios-spm.git", from: "1.2.0-beta.1")
],
targets: [
.target(name: "YourApp", dependencies: [
.product(name: "BillDogFull", package: "billdog-ios-spm")
])
]Every published version is currently a prerelease, so in Xcode's dialog choose Exact Version (or Up to Next Major and type the version) and enter the version shown above.
Import the single module BillDogFull. Sub-module imports such as import BillDogAnalytics don't resolve for binary packages. CocoaPods trunk goes read-only on 2 December 2026, so use Swift Package Manager for new apps.
2. Set up the product, paywall and placement
12 minYour app asks BillDog for a placement (a named moment such as onboarding), and the dashboard decides which paywall to show there. That means you can change the paywall later without shipping an app update. Four things need to be connected: a product, an entitlement it grants, an offering that sells it, and a placement that serves the offering's paywall.
- Use the Public Sandbox API Key shown when you created the project. It starts with
bd_public_test_. Didn't save it? The API Keys list shows only a prefix, so make a new one: open Integration & Data → API Keys, click Generate API Key, enter a Key Name, choose Environment: Sandbox and Key Type: Public (Client), then copy the key from the dialog. It is shown only once. Ship only public keys in an app;bd_secret_keys are for servers. - Open Monetization → Products and click New Product. Keep Product Kind: Store. The Product Identifier is BillDog's own ID for the product. Set Product Type to Subscription and choose a Subscription Duration. Put the exact store IDs in App Store Product ID and Play Store Product ID. A product with no ID for a store is not served on that platform. Enable Web Checkout is on by default; its price is only used for Stripe on the web. Products not in the store yet? See App Store setup or Google Play setup.
- Open Monetization → Entitlements, click New Entitlement, use the identifier
premium(with any Display Name), and under Product Mapping tick the product. New projects also come with aproentitlement and a Default Offering; this codelab uses its own. Without this mapping a purchase succeeds but unlocks nothing. - Open Monetization → Offerings, click New Offering, give it an Identifier and Display Name, tick Mark as current offering and click Create Offering. The offering editor opens: click Add Product, tick your product, type a Package Identifier such as
monthly, click Add Package, then Save Changes. - Open Paywalls & Funnels → Create New → Single Paywall, choose Use Template and pick one. In the builder, open the Products panel (the box icon in the left rail) and choose your offering under Offering.
- Templates are designs: their buttons aren't wired to buy anything. Select the main button, and under Tap Actions click Add First Action and choose Purchase. Give the close button (or a secondary button) a Close Paywall action if it has none: publishing refuses a paywall with no way out.
- Click Publish (then Save & Publish). A warning that "nothing on this paywall starts a purchase" means the main button still has no Purchase action. Check the paywall shows Live under Paywalls & Funnels → All Paywalls. An unpublished paywall serves nothing.
- Open Monetization → Placements, click Create Placement, set the Identifier to
onboardingand a Display Name, and click Create. Then click the link icon on the placement's row, tick your offering, tick Default and click Link Offerings. - In the same Create Placement dialog (or later on the placement's page), turn on Requires access and choose
premiumas the Required Entitlement. Subscribers then skip the paywall instead of seeing it again.
Placement identifiers are case-sensitive. A mistyped identifier is created as an empty placement (you'll see it under Placements), and register comes back with a "no paywall configured" error. If nothing shows, see Fix a paywall that doesn't show.
3. Configure the SDK at launch
3 minCall configure once, as early as possible. In SwiftUI, that is your App initializer. Use the test key while you develop.
import SwiftUI
import BillDogFull
@main
struct MyApp: App {
init() {
BillDog.shared.configure(
config: BillDogConfig(
apiKey: "bd_public_test_YOUR_KEY",
enableLogging: true
)
)
}
var body: some Scene {
WindowGroup { ContentView() }
}
}There is no initialize call: configure(config:) is the only entry point. With enableLogging: true the Xcode console shows what the SDK fetched.
4. Show the paywall for a placement
5 minregister(placement:) fetches the paywall linked to the placement, presents it from the top view controller and returns a PlacementResult when the user is done. Because the placement has Requires access on, a user who already holds premium gets .entitled and sees nothing. If the placement has no paywall linked, you get .error with a "no paywall configured" message.
import SwiftUI
import BillDogFull
struct ContentView: View {
@State private var isPro = false
var body: some View {
VStack(spacing: 16) {
Text(isPro ? "Premium unlocked" : "Free plan")
Button("Unlock Premium") {
Task {
do {
switch try await BillDog.shared.register(placement: "onboarding") {
case .entitled, .purchased, .restored:
isPro = true
case .error(let error):
print("Placement failed: \(error)")
default:
break // .dismissed, .holdout, .oauthSuccess
}
} catch {
print("Placement failed: \(error)")
}
}
}
}
}
}Run the app and tap the button. You should see the paywall you published in step 2. To buy in the sandbox, follow Test real App Store purchases; to connect your products, see Connect the App Store.
5. Unlock content with the entitlement
3 minCheck access when the app starts, not only after a purchase, so returning subscribers are unlocked straight away.
.task {
if let info = try? await BillDog.shared.getCustomerInfo() {
isPro = info.hasEntitlement("premium")
}
}hasEntitlement returns true only for an active entitlement, so an expired subscription locks again automatically.
6. Add Restore Purchases
3 minApp Review expects a restore control. Call it only from a tap, because it can show the App Store sign-in sheet. A store failure comes back as .failed; the call throws only if the SDK isn't configured. Afterwards, refresh with getCustomerInfo(forceRefresh: true) so the cached answer isn't reused.
Button("Restore Purchases") {
Task {
do {
switch try await BillDog.shared.restorePurchases() {
case .restored(let items): print("Restored \(items.count)")
case .failed(let error): print("Restore failed: \(error)")
@unknown default: break
}
let info = try await BillDog.shared.getCustomerInfo(forceRefresh: true)
isPro = info.hasEntitlement("premium")
} catch {
print("Restore failed: \(error)")
}
}
}7. Optional: identify signed-in users
2 minBillDog creates an anonymous ID on first launch. When a user signs in, identify them so their purchases follow them to other devices.
func signedIn(as userId: String) {
Task {
do {
_ = try await BillDog.shared.identify(userId: userId)
} catch {
print("Identify failed: \(error)")
}
}
}
// On sign-out: switches to a new anonymous ID
func signedOut() {
BillDog.shared.logOut()
}Before release, swap the test key for the bd_public_live_ key. Next, try running an A/B test on this paywall.