ConnectSDK

The main entry point for all Connect iOS SDK operations. Accessed via the shared singleton ConnectSDK.shared.

Platform: iOS 15.1+
Isolation: @MainActor
Declared in: ConnectSDK


Getting the shared instance

ConnectSDK.shared is the single access point for the SDK. All methods and sub-interfaces are accessed through it.

ConnectSDK.shared

Enabling and disabling

enable(appKey:postURL:push:)

Initializes the SDK with credentials. Call this in application(_:didFinishLaunchingWithOptions:).

ConnectSDK.shared.enable(
    appKey: "YOUR_APP_KEY",
    postURL: "https://collector.example.com/collectorPost",
    push: .automatic   // defaults to .off
)
⚠️

Important

Do not initialize the SDK in .onAppear, .task, or View.init(). These run after didFinishLaunching returns, and cold-start push notification actions will be silently lost.

UIKit apps already have an AppDelegate — just add the enable() call to the existing application(_:didFinishLaunchingWithOptions:).

SwiftUI apps have no AppDelegate by default. Create one and connect it via @UIApplicationDelegateAdaptor so the SDK initializes at the correct point in the app lifecycle:

@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

final class AppDelegate: NSObject, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        ConnectSDK.shared.enable(
            appKey: "YOUR_APP_KEY",
            postURL: "https://collector.example.com/collectorPost"
        )
        return true
    }
}

enable(with:)

Initializes the SDK with a full typed ConnectConfig configuration object.

ConnectSDK.shared.enable(with: config)

See the ConnectConfig reference for all available options.

disable()

Disables the SDK and stops all data capture.

ConnectSDK.shared.disable()

flush()

Immediately flushes all buffered messages to the backend without waiting for the next automatic POST interval.

ConnectSDK.shared.flush()

Status

PropertyTypeDescription
isEnabledBoolWhether the SDK is currently enabled.
frameworkVersionStringThe SDK version string.
currentSessionIdString?The active session identifier, or nil if no session is active.

Sub-interfaces

PropertyTypeDescription
identityConnectIdentityIdentity signal logging. Always available; no push configuration required.
pushConnectPushPush notification interface. Throws ConnectError.pushNotEnabled if push was not configured at enable() time.

Session management

MethodReturnsDescription
pause()BoolPauses data capture. Use for sensitive screens.
resume()BoolResumes data capture after a pause.
resume(pageName:)BoolResumes data capture and sets the current screen name.
setCurrentScreen(pageName:)BoolSets the logical screen name without resuming a paused session.
startNewSession()BoolForces a new session boundary immediately.
requestManualPost()VoidTriggers an immediate data upload. Requires ManualPostEnabled in configuration.

Device identity

Method / PropertyReturnsDescription
setDeviceId(_:)BoolSets a custom device identifier.
deviceIdString?Returns the current device identifier.
setCXAAdvertisingId(_:)BoolSets the CXA advertising identifier (IDFA).
cxaAdvertisingIdString?Returns the current CXA advertising identifier.
applicationContextNameString?Returns the application context name.

Network

MethodDescription
setHTTPHeaders(_:)Replaces all additional HTTP headers on payload requests.
addHTTPHeader(_:forName:)Appends a single HTTP header.
setHTTPCookies(_:)Replaces all additional HTTP cookies.
addHTTPCookie(_:)Appends a single HTTP cookie.
sessionize(request:inout)Attaches the Connect session cookie to a URLRequest. Returns Bool.
setPostMessageURL(_:)Changes the collector endpoint URL. Persisted across sessions.
setKillSwitchURL(_:)Changes the remote kill-switch URL. Persisted across sessions.

Capture configuration

MethodReturnsDescription
setLogLevel(_:forEvent:)BoolSets the logging level for a named capture event.
logLevel(forEvent:)UIntReturns the current logging level for a named event.
setConfigurableItem(_:value:)BoolSets a raw configuration item by key.
valueForConfigurableItem(_:)Any?Returns the current value of a configuration item.
layoutConfigItems[AnyHashable: Any]?The AutoLayout configuration dictionary.

WebView integration

Use these methods to support hybrid apps that embed web content in a WKWebView.

MethodReturnsDescription
isHybridBridgeRequest(_:webView:)BoolDetects SDK bridge requests in WKNavigationDelegate. Call from decidePolicyForNavigationAction:decisionHandler:.
injectHybridBridge(into:)BoolInjects Connect bridge JavaScript into a WKWebView. Call from webView(_:didFinish:).
sendEvent(_:)VoidForwards a UIEvent to the SDK for capture.
sendAction(_:to:from:for:)VoidForwards a UIAction for capture.

Example

// WKNavigationDelegate
func webView(
    _ webView: WKWebView,
    decidePolicyFor navigationAction: WKNavigationAction,
    decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
) {
    if ConnectSDK.shared.isHybridBridgeRequest(navigationAction.request, webView: webView) {
        decisionHandler(.cancel)
    } else {
        decisionHandler(.allow)
    }
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    ConnectSDK.shared.injectHybridBridge(into: webView)
}