Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions content/docs/ios/sdk-reference/Superwall.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Provides access to the configured Superwall instance after calling [`configure()
```swift
public static var shared: Superwall { get }
public var eventTrackingBehavior: EventTrackingBehavior { get set }

@Published public var configurationStatus: ConfigurationStatus { get }
public var isPaywallPresented: Bool { get }
public var latestPaywallInfo: PaywallInfo? { get }

public func getAssignments() -> [Assignment]
public func togglePaywallSpinner(isHidden: Bool)
```

## Parameters
Expand Down Expand Up @@ -114,13 +121,66 @@ let deviceAttributes = await Superwall.shared.getDeviceAttributes()
print("Device attributes: \(deviceAttributes)")
```

Observe configuration status:
```swift
// .pending until configuration finishes, then .configured or .failed
switch Superwall.shared.configurationStatus {
case .pending:
showLoadingState()
case .configured:
showPaywallEntryPoints()
case .failed:
showFallbackUI()
}

// It's a @Published property, so you can bind to it in SwiftUI or Combine
Superwall.shared.$configurationStatus
.sink { status in
print("Superwall configuration is now \(status)")
}
.store(in: &cancellables)
```

Check whether a paywall is on screen:
```swift
if Superwall.shared.isPaywallPresented {
// Don't push another screen on top of the paywall
return
}

// Inspect the most recently presented paywall
if let info = Superwall.shared.latestPaywallInfo {
print("Last paywall: \(info.identifier), experiment: \(info.experiment?.id ?? "none")")
}
```

Confirm all experiment assignments:
```swift
// Get all experiment assignments
let assignments = await Superwall.shared.confirmAllAssignments()
print("Confirmed \(assignments.count) assignments")
```

Read already-confirmed assignments:
```swift
// Synchronous, and does not confirm anything new — returns the assignments
// already stored on device. Use confirmAllAssignments() to confirm them first.
let assignments = Superwall.shared.getAssignments()
```

Show a spinner while doing async work from a custom paywall action:
```swift
func handleCustomPaywallAction(withName name: String) {
guard name == "restore_from_backend" else { return }

Superwall.shared.togglePaywallSpinner(isHidden: false)
Task {
await syncEntitlementsFromServer()
Superwall.shared.togglePaywallSpinner(isHidden: true)
}
}
```

Manually refresh configuration (development-only):
```swift
// Useful when hot-reloading paywalls during development
Expand Down
10 changes: 10 additions & 0 deletions content/docs/ios/sdk-reference/SuperwallOptions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class SuperwallOptions: NSObject {
public var isExternalDataCollectionEnabled: Bool
public var testModeBehavior: TestModeBehavior
public var localResources: [String: AssetResource]
public var maxConfigRetryCount: Int
}
```

Expand Down Expand Up @@ -93,6 +94,12 @@ public final class SuperwallOptions: NSObject {
"A dictionary mapping resource IDs to local file URLs or asset catalog images. See [`localResources`](/ios/sdk-reference/localResources) for the property schema and the [Local Resources guide](/ios/guides/local-resources) for setup details.",
default: "[:]",
},
maxConfigRetryCount: {
type: "Int",
description:
"How many times the SDK retries fetching configuration after a network failure before giving up. Lower it to have [`register(placement:)`](/ios/sdk-reference/register) call the [`PaywallPresentationHandler`](/ios/sdk-reference/PaywallPresentationHandler) `onError` handler sooner on a bad connection. Values below `0` are clamped to `0`.",
default: "6",
},
}}
/>

Expand Down Expand Up @@ -127,6 +134,9 @@ options.shouldBypassAppTransactionCheck = true
// Control SDK event collection
options.eventTrackingBehavior = .superwallOnly

// Fail faster on a poor connection instead of retrying 6 times
options.maxConfigRetryCount = 2

// Use with configure
Superwall.configure(
apiKey: "pk_your_api_key",
Expand Down