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.
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
| Item | Requirement |
|---|---|
| iOS | 13.0 or higher |
| tvOS, macOS | 13.0 or higher |
| watchOS | 6.0 or higher |
| Swift | 5.9 or higher |
| Xcode | 26 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-sdkFor a project managed by 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.
.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
use_frameworks!
target 'YourApp' do
pod 'SophonzIO'
endpod installThe podspec points at the v-prefixed tag (v1.0.0). It is not published to trunk yet, so point the pod at the repository:
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.
<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>| Key | Sent as | Notes |
|---|---|---|
CollectorURL | — | Base URL of the collector; do not append /v1/... |
AppKey | service.key | The sk_… minted by the portal |
AppName | service.name | How the portal finds your app. Must be the registered name |
Project | service.namespace | Logical grouping |
DeploymentEnvironment | deployment.environment.name | production, 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.
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
- Configuration — options and capture services
- Instrumentation — what is captured automatically
- Examples — finished shapes