Skip to content

Kotlin Multiplatform & iOS (beta)

Report crashes and errors from shared Kotlin code, and monitor your iOS app through the same SDK.

Early access beta

Kotlin Multiplatform and iOS support is in beta. The core is the same SDK that powers our Android and Flutter releases, but the setup and API may still change before general availability. Contact us to join the beta.

What the beta covers

  • Shared code (commonMain): identify, reset, track, screen, recordException, setEnabled and flush work from shared Kotlin.
  • Android target: everything in the Android SDK: crashes, ANRs, OkHttp network capture, screens and lifecycle events.
  • iOS: uncaught exceptions and crash signals are captured automatically once the SDK starts, with the same on-device queue as Android. iOS 14 or later.
  • iOS, from 0.4.0: lifecycle events ($app_opened, $session_started, $app_backgrounded and so on), a presence heartbeat every 45 seconds in the foreground, a session saved on the device so a restart within 30 minutes continues it, and each UIViewController shown recorded as a screen (captureScreens).

Not in the beta yet

There's no Ktor client plugin, so network capture from shared code isn't automatic. On iOS, URLSession requests aren't captured automatically either. See iOS network capture below.

Kotlin Multiplatform setup

Add the shared core to commonMain and the Android runtime to androidMain:

shared/build.gradle.kts
kotlin {    sourceSets {        commonMain.dependencies {            implementation("com.codeskop.sdk:tracker-core:0.4.0")        }        androidMain.dependencies {            implementation("com.codeskop.sdk:tracker-android:0.4.0")            implementation("com.codeskop.sdk:tracker-okhttp:0.4.0") // optional network capture        }    }}

Initialize on each platform, then call the SDK from shared code:

androidMain
// androidMain: initialize once, e.g. in Application.onCreateCodeskopAndroid.init(    context,    CodeskopConfig(apiKey = BuildConfig.CODESKOP_KEY),)
commonMain
// commonMain: identify and report from shared codeCodeskop.identify(userId = user.id) try {    syncCart()} catch (e: Exception) {    Codeskop.recordException(e)}

The Android side behaves exactly like the Android SDK, including initialization from the manifest instead of code.

iOS setup

1. Add the Swift package

During the beta, the iOS SDK is distributed as a Swift package from a private repository. We'll give your team access when you join the beta. Then add it in Xcode or Package.swift and add the CodeskopSDK product to your app target:

Package.swift
.package(url: "https://github.com/Codeskop-io/mobile-sdk.git", from: "0.4.0")

2. Start the SDK and identify users

Call start once at launch, for example in your AppDelegate or App initializer. It returns immediately and does its setup in the background.

AppDelegate.swift
import CodeskopSDK // Swift needs every CodeskopConfig parameter spelled outlet config = CodeskopConfig(    apiKey: "cs_live_pk_xxx",    endpoint: "https://api.codeskop.com",    environment: "production",    sampleRates: [:],    captureNetwork: true,    captureHeaders: true,    captureBodies: false,    redactHeaders: ["authorization", "cookie", "set-cookie"],    redactQueryKeys: ["token", "apikey", "password", "secret"],    maxQueueMb: 10,    heartbeatEnabled: true,    flushBatchSize: 50,    captureExceptionMessages: false,    captureScreens: true)CodeskopIos.shared.start(config: config) // At loginCodeskop.shared.identify(userId: user.id, traits: [:])

Why every parameter?

Kotlin's default values don't carry over to the generated Swift initializer, so each CodeskopConfig field has to be passed. Use the values above as your defaults; they match the Android defaults. See configuration for what each one does, and Exception messages to send messages instead of [REDACTED].

Product analytics on iOS

On Growth and Scale, track events and screens from Swift. View controllers are recorded as screens by class name; navigation, tab and split containers, alerts and SwiftUI hosting controllers are skipped, so name SwiftUI screens yourself. Taps aren't recorded automatically: track the ones that matter as interaction.

Swift
// Product analytics (Growth and Scale). category is optional (0.4.0+).Codeskop.shared.track(name: "order_completed", properties: ["value": 49.99, "currency": "KES"])Codeskop.shared.track(name: "delivery_method_selected", properties: ["method": "pickup"], category: "interaction") // View controllers are recorded as screens automatically. Name a SwiftUI view yourself:Codeskop.shared.screen(name: "Checkout", properties: [:]) // On logout: clears the user and starts a new anonymous idCodeskop.shared.reset()

From shared Kotlin code, the same call takes a named category:

commonMain
// commonMainCodeskop.track("login_failed", mapOf("reason" to "invalid_password"), category = "identity")

See Track events & screens and the event model.

iOS network capture

To report failing requests on iOS, register a small URLProtocol subclass in your app that forwards failures to Codeskop.shared.captureApiError(call:). We share a reference implementation with beta teams. It's under 100 lines you copy into your project.

Next steps