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.sharedEnabling 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
)
ImportantDo not initialize the SDK in
.onAppear,.task, orView.init(). These run afterdidFinishLaunchingreturns, 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
| Property | Type | Description |
|---|---|---|
isEnabled | Bool | Whether the SDK is currently enabled. |
frameworkVersion | String | The SDK version string. |
currentSessionId | String? | The active session identifier, or nil if no session is active. |
Sub-interfaces
| Property | Type | Description |
|---|---|---|
identity | ConnectIdentity | Identity signal logging. Always available; no push configuration required. |
push | ConnectPush | Push notification interface. Throws ConnectError.pushNotEnabled if push was not configured at enable() time. |
Session management
| Method | Returns | Description |
|---|---|---|
pause() | Bool | Pauses data capture. Use for sensitive screens. |
resume() | Bool | Resumes data capture after a pause. |
resume(pageName:) | Bool | Resumes data capture and sets the current screen name. |
setCurrentScreen(pageName:) | Bool | Sets the logical screen name without resuming a paused session. |
startNewSession() | Bool | Forces a new session boundary immediately. |
requestManualPost() | Void | Triggers an immediate data upload. Requires ManualPostEnabled in configuration. |
Device identity
| Method / Property | Returns | Description |
|---|---|---|
setDeviceId(_:) | Bool | Sets a custom device identifier. |
deviceId | String? | Returns the current device identifier. |
setCXAAdvertisingId(_:) | Bool | Sets the CXA advertising identifier (IDFA). |
cxaAdvertisingId | String? | Returns the current CXA advertising identifier. |
applicationContextName | String? | Returns the application context name. |
Network
| Method | Description |
|---|---|
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
| Method | Returns | Description |
|---|---|---|
setLogLevel(_:forEvent:) | Bool | Sets the logging level for a named capture event. |
logLevel(forEvent:) | UInt | Returns the current logging level for a named event. |
setConfigurableItem(_:value:) | Bool | Sets 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.
| Method | Returns | Description |
|---|---|---|
isHybridBridgeRequest(_:webView:) | Bool | Detects SDK bridge requests in WKNavigationDelegate. Call from decidePolicyForNavigationAction:decisionHandler:. |
injectHybridBridge(into:) | Bool | Injects Connect bridge JavaScript into a WKWebView. Call from webView(_:didFinish:). |
sendEvent(_:) | Void | Forwards a UIEvent to the SDK for capture. |
sendAction(_:to:from:for:) | Void | Forwards 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)
}Updated about 2 hours ago
