stubkit docs

iOS quickstart

stubkit's Swift SDK wraps StoreKit 2 and syncs transactions with the stubkit backend so your entitlements work across devices and platforms. This guide takes you from zero to a working paywall in about 15 minutes.

Install

Add the package via Swift Package Manager:

.package(url: "https://github.com/stubkithq/stubkit-swift.git", from: "1.0.1")

Configure

At app launch (App delegate or @main struct), configure the SDK with your publishable key and the current user's id:

import stubkit

@main
struct MyApp: App {
    init() {
        StubkitPurchases.shared.configure(
            apiKey: "pk_live_...",
            appId: "notesam",
            userId: currentUser.id.uuidString
        )
    }
}

The userId must be a UUID string. stubkit passes this as StoreKit's appAccountToken so renewals and refunds stay attached to the same user across devices.

Show the paywall

StubkitPaywallView renders a SwiftUI paywall from your offering config. Put it behind any upgrade CTA:

import SwiftUI
import stubkit

struct UpgradeButton: View {
    @State private var showPaywall = false

    var body: some View {
        Button("Upgrade") { showPaywall = true }
            .sheet(isPresented: $showPaywall) {
                StubkitPaywallView(
                    apiKey: "pk_live_...",
                    appId: "notesam",
                    slug: "default"
                ) { outcome in
                    if case .purchased = outcome { showPaywall = false }
                }
            }
    }
}

Check entitlements

Use the local cache (populated on every purchase sync) to check synchronously:

let isPro = EntitlementCache.shared.isActive(
    appId: "notesam",
    userId: userId,
    entitlementId: "pro"
)

Or hit the REST API directly for a source-of-truth check: GET /v1/entitlement/notesam/{user_id}.

Restore purchases

Button("Restore") {
    Task { try? await StubkitPurchases.shared.restore() }
}

Testing with sandbox

Create a Sandbox Tester in App Store Connect under Users & Access → Sandbox Testers. Sign in on the device's Settings app under App Store → Sandbox Account. Purchases made with a sandbox account are free and renew on an accelerated schedule (monthly subs renew every 5 minutes).

Next steps