Installation

Adding the Apple SDK with Swift Package Manager or CocoaPods, and starting it in your app.

Installation is adding the package and calling Sophonz.start(options:) once at launch. Capture services handle the instrumentation, so there is no code to add per screen or per network call.

Starting the Apple SDK

Quick start

Enter the collector URL, project and app key below and pick a tab (Swift · Objective-C) to generate the initialization code from those values. Advanced options are behind the "Advanced options" toggle.

// AppDelegate.swift
import SophonzCore

let option = Sophonz.Options(
    project: "sophonz",
    appKey:  "sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz",
    endpoints: Sophonz.Endpoints(collectorURL: "https://in.sophonz.ai"))

Sophonz.setup(options: option)?.start()

NOTE — Telemetry without an app key is dropped silently

The collector runs service_key_mode: enforce. Telemetry that carries no key, or a key it cannot resolve, is discarded without an error — so a build configured without one looks like it is working and produces nothing.

Requirements

ItemRequirement
iOS13.0 or higher
tvOS, macOS13.0 or higher
watchOS6.0 or higher
Swift5.9 or higher
Xcode26 or higher (to build the SDK)

Swift Package Manager

Add the repository URL under File > Add Package Dependencies in Xcode.

https://github.com/sophonz-labs/sophonz-apple-sdk

For a project managed by Package.swift:

Package.swift
dependencies: [
  .package(url: "https://github.com/sophonz-labs/sophonz-apple-sdk", from: "1.0.0")
],
targets: [
  .target(
    name: "YourApp",
    dependencies: [
      .product(name: "SophonzIO", package: "sophonz-apple-sdk")
    ]
  )
]

SophonzIO is the only product your app links. It vends the public Sophonz class and its options, with the implementation behind it.

NOTE — The other library products

The package also exports SophonzCore, SophonzSemantics, SophonzMacros, and SophonzKSCrashBacktraceSupport. A normal app needs none of them — SophonzIO pulls in what it needs. Modules named *Internal are not a supported API surface.

Prebuilt XCFramework

To avoid building from source, use the XCFramework attached to each release as SophonzIO-<version>.xcframework.zip, alongside its .sha256.

Package.swift
.binaryTarget(
  name: "SophonzIO",
  url: "https://github.com/sophonz-labs/sophonz-apple-sdk/releases/download/v1.0.0/SophonzIO-1.0.0.xcframework.zip",
  checksum: "<contents of the .sha256 file>"
)

In an Xcode project, unzip it and drag it into the target's Frameworks, Libraries, and Embedded Content, set to Embed & Sign.

CocoaPods

Podfile
use_frameworks!
 
target 'YourApp' do
  pod 'SophonzIO'
end
pod install

The podspec points at the v-prefixed tag (v1.0.0). It is not published to trunk yet, so point the pod at the repository:

Podfile
pod 'SophonzIO', :git => 'https://github.com/sophonz-labs/sophonz-apple-sdk.git', :tag => 'v1.0.0'

Starting the SDK

Sophonz.start(options:) is a static, throwing method. Call it once at launch, on the main thread.

Read the configuration from your target's Sophonz-Info.plist so the app key is not committed and can change per build configuration.

Sophonz-Info.plist
<key>CollectorURL</key>
<string>https://in.sophonz.ai</string>
<key>AppKey</key>
<string>$(SOPHONZ_APP_KEY)</string>
<key>AppName</key>
<string>My App</string>
<key>Project</key>
<string>my-project</string>
<key>DeploymentEnvironment</key>
<string>production</string>
KeySent asNotes
CollectorURL—Base URL of the collector; do not append /v1/...
AppKeyservice.keyThe sk_… minted by the portal
AppNameservice.nameHow the portal finds your app. Must be the registered name
Projectservice.namespaceLogical grouping
DeploymentEnvironmentdeployment.environment.nameproduction, staging, …

CAUTION — AppName is the portal's join key

app.sophonz.ai matches an app on (project, service.name). Change this string and the collector keeps accepting your telemetry while the app's page goes blank — which looks exactly like delivery stopping. Use the name the app is registered under.

NOTE — $(…) is only expanded in the target's Info.plist

Xcode expands build settings in the target's Info.plist and nowhere else. A configuration plist copied in as a resource ships the literal $(SOPHONZ_APP_KEY), so generate it in a build phase instead. The SDK treats both an unexpanded $(…) and an empty string as absent.

YourApp.swift
import SwiftUI
import SophonzIO
 
@main
struct YourApp: App {
  init() {
    guard let options = Sophonz.Options.fromPlist() else {
      // No collector or no key: a build to leave unstarted rather than start blind.
      return
    }
    do {
      try Sophonz.start(options: options)
    } catch {
      // Do not let a failed start block the app. No instrumentation is
      // better than no launch.
      print("[sophonz] failed to start: \(error)")
    }
  }
 
  var body: some Scene {
    WindowGroup { ContentView() }
  }
}

In a UIKit app, make the same call from application(_:didFinishLaunchingWithOptions:).

Passing the values in code

try Sophonz.start(options: .withCollector(
  url: "https://in.sophonz.ai",
  appKey: "sk_…",
  appName: "My App",
  project: "my-project",
  deploymentEnvironment: "production"
))

After starting, everything else goes through Sophonz.shared.

if Sophonz.shared.isSDKEnabled {
  // Collecting
}

Naming SwiftUI screens

A UIKit app gets screen names for free, because every screen is a view controller. SwiftUI does not: a NavigationStack is one view controller — UIKitNavigationController — for the whole app, so without help every span in the app is stamped with that one name and screen-level analysis has nothing to group by.

Each screen names itself:

GalleryView()
  .sophonzScreen("Gallery")

sophonzScreen sets the screen name and traces the view. Use sophonzTrace(_:) for a view that is part of a screen rather than a screen. Spans read the current screen when they start, so a request that outlives the screen still belongs to the screen that made it.

When telemetry is sent

Spans and logs are written to disk as they end, and uploaded when a session part ends — when the app goes to the background, or on the next launch after a kill. There is no periodic timer.

An app left in the foreground for ten minutes holds ten minutes of telemetry on disk and has sent none of it. That accounts for most reports of data "arriving intermittently"; it is not the transport.

Starting with your own exporter

This mode replaces the Sophonz collector with exporters of your own. No upload is created at all, so exporters are the only way data leaves the device — which is why otel: is a required argument rather than an optional one.

import SophonzIO
import OpenTelemetrySdk
 
let otel = Sophonz.OTelOptions(
  spanExporters: [myOtlpSpanExporter],
  logExporters: [myOtlpLogExporter]
)
 
try Sophonz.start(options: .withLocalConfiguration(otel: otel))

OTelOptions takes resource, spanProcessors, spanExporters, logProcessors, and logExporters. service.name, service.version, and telemetry.sdk.language are always set by the SDK and cannot be overridden through resource.

Objective-C projects

The SDK is a Swift module, so Objective-C reaches it through the generated interface rather than a bridging header. Keeping the startup code in one Swift file and calling that function from Objective-C is simpler.

Next