Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io
    Get started
    iOS
    Beginner
    31 min

    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 premium entitlement 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 min

    In 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:

    Package.swift
    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 min

    Your 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.

    1. 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.
    2. 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.
    3. 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 a pro entitlement and a Default Offering; this codelab uses its own. Without this mapping a purchase succeeds but unlocks nothing.
    4. 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.
    5. 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.
    6. 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.
    7. 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.
    8. Open Monetization → Placements, click Create Placement, set the Identifier to onboarding and 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.
    9. In the same Create Placement dialog (or later on the placement's page), turn on Requires access and choose premium as 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 min

    Call configure once, as early as possible. In SwiftUI, that is your App initializer. Use the test key while you develop.

    MyApp.swift
    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 min

    register(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.

    ContentView.swift
    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 min

    Check access when the app starts, not only after a purchase, so returning subscribers are unlocked straight away.

    Swift
    .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 min

    App 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.

    Swift
    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 min

    BillDog creates an anonymous ID on first launch. When a user signs in, identify them so their purchases follow them to other devices.

    Swift
    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.

    Frequently asked questions

    iOS 15.0. The package is built with Swift 6.3, so you need Xcode 26 or later to build against it.

    Yes. The app only asks for a placement such as onboarding. Which paywall that placement shows is set in the dashboard, so you can edit, swap or A/B test it without releasing a new build.

    The most common cause is a placement with no paywall linked: register returns an error with a no paywall configured message. Check that the offering is linked to the placement as Default and that its paywall is published.

    No. The only entry point is BillDog.shared.configure(config:), called once at launch with a BillDogConfig that holds your public API key.

    No. The SDK loads products, runs the StoreKit purchase and records the transaction. If you already have your own purchase code, you can pass a purchase controller to configure instead.

    Reference

    Ship it on a free project

    Create a project, grab your SDK key and follow along. Sandbox purchases and data stay separate from production, so test transactions never mix with real revenue.

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.