iOS SDK

The Swift SDK supports iOS 15+, StoreKit 2, signed device sessions, durable purchase/event queues and subject-scoped entitlement caching.

The source is private for now and a public release is pending, so there is no public install command yet.

Configure

Add the repository as a local Swift package or select codex/step-22-ios-sdk. Import SubHeroIntegration and retain one SubHero instance per project/environment.

swift code
let sdk = try SubHero.configure(
  publishableKey, origin: apiOrigin, projectID: projectID, appVersion: appVersion)
let products = try await sdk.products()
let paywall = try await sdk.paywall("main")
try await sdk.paywallShown(paywall) // Only when actually presented.
let result = try await sdk.purchase(products[0], paywall: paywall)
let access = try await sdk.entitlements(forceRefresh: true)

Runtime catalog reads exclude history-derived and retired products and select the known session’s platform. Product prices and offers come from StoreKit. A fetched paywall supplies ordered IDs and remote configuration, not a price quote or entitlement. In the console, open the project’s Products → Paywalls editor. As an administrator, create main, select and order sellable catalog products, enter public remote-config JSON, and enable the placement. Use a placement ID beginning with a letter or digit. Remote config is limited to 16 KiB and is readable by app users: never include secrets. Disabled or missing placements return 404. The host owns presentation and reports paywall_closed on actual dismissal. Experiment context is returned by the server when available; the SDK never creates assignments.

Identity and events

swift code
try await sdk.identify(identityJWTFromYourBackend)
try await sdk.track("article_read", properties: ["category": .string("news")])
try sdk.setDeviceIds(["app_instance_id": realFirebaseID], consentGranted: consent)
try await sdk.restore()
try await sdk.logout()

Never embed a server key or identity-signing secret. Identify requires a single-use JWT from your authenticated backend. Logout clears grants before waiting for network revocation. Pending work retains its originating subject; only a confirmed anonymous merge reassigns it.

Register custom event names first. Events batch at 20 items/every 10 seconds, persist across restart and honor retry delays. eventDidReject surfaces item rejections. Tracking before the first successful server session cannot invent an anonymous identity; retry once connected. Queue overflow is explicit at 1000 events/1 MiB. setDeviceIds accepts real, consented provider IDs; it never substitutes an installation UUID for a Firebase App Instance ID. Passing false clears analytics identifiers.

Purchase outcomes and verification

A StoreKit proof is persisted before HTTP. A verified persisted proof can finish even when the server reports unknown binding; a 409 is terminal locally and never grants access. Temporary failures remain awaitingServer. Restoring replays verified current and unfinished transactions. Store-local access remains separate from cross-device server grants.

The repository includes a runnable sandbox example, unit tests, hosted StoreKit configuration and DocC generation support; a published DocC reference remains pending. Supply your sandbox project/key at runtime; no credentials are committed. Verify a real App Store sandbox purchase, renewal, restore, offline relaunch and account switch before production rollout. SDK code and simulator fixtures do not substitute for that owner-controlled check.

Authentication · API reference · Migration guides