This example demonstrates how to use Spectra Logger in a native iOS application using Swift and SwiftUI. It uses the unified Compose Multiplatform UI SDK for a consistent debugging experience.
- Xcode 15.0 or later
- iOS 15.0 or later
- macOS with Apple Silicon or Intel processor
-
Ensure the XCFrameworks are built: From the project root, run:
./scripts/build/build-xcframework.sh
This will use the official KMP Gradle tasks to build
SpectraLoggerandSpectraLoggerUIframeworks and place them inbuild/xcframework/. -
Open the Xcode project:
cd examples/ios-native open SpectraExample.xcodeproj -
Build and run:
- Select an iPhone simulator.
- Press Cmd+R to run.
This example app uses Swift Package Manager to depend on:
SpectraLogger(Core Logic) - Binary XCFrameworkSpectraLoggerUI(Unified UI) - Binary XCFramework
The root Package.swift is configured to look for these frameworks in build/xcframework/ during local development.
- ✅ All Log Levels: Verbose, Debug, Info, Warning, Error, Fatal
- ✅ Structured Logging: Key-value metadata support
- ✅ Error Tracking: Full stack trace capture with line numbers
- ✅ Adaptive UI: Unified Compose Multiplatform UI that works identically on iOS and Android.
- ✅ Logs Tab: Real-time log display with multi-level filtering and search.
- ✅ Network Tab: HTTP request/response logging with header and body inspection.
- ✅ Settings Tab: Theme control, storage statistics, and log clearing.
- ✅ Native Share Sheet: Export logs via iOS native sharing.
examples/ios-native/
├── SpectraExample.xcodeproj/ # Xcode project
├── SpectraExample/ # Application source files
│ ├── SpectraExampleApp.swift # App entry point
│ ├── MainAppView.swift # Main screen
│ ├── SpectraLoggerView.swift # SwiftUI wrapper for SpectraLoggerUI
│ └── ViewModels/ # Demo logic
└── README.md # This file
In SpectraExampleApp.swift:
import SpectraLogger
@main
struct SpectraExampleApp: App {
init() {
SpectraLogger.shared.configure { config in
config.appContext = AppContext(
sessionId: UUID().uuidString,
appVersion: "1.0.4",
osName: "iOS",
environment: "development"
)
}
}
}The SpectraLoggerView.swift file wraps the Kotlin-exported UIViewController using UIViewControllerRepresentable:
import SwiftUI
import SpectraLoggerUI
struct SpectraLoggerView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
return SpectraLoggerViewControllerKt.SpectraLoggerViewController(onDismiss: {
// Handle dismissal
})
}
}- Ensure you have run
./scripts/build/build-xcframework.shfrom the project root. - Verify that
build/xcframework/contains both.xcframeworkfolders. - Clean the build folder in Xcode (Cmd+Shift+K).
Simulator builds do not require code signing. For physical devices, ensure your team is selected in the "Signing & Capabilities" tab.
If you encounter a crash with the message CADisableMinimumFrameDurationOnPhone is missing, ensure your Info.plist (or Target Build Settings) has this key:
- Key:
CADisableMinimumFrameDurationOnPhone - Value:
YES(Boolean)
Why is this required? Compose Multiplatform (via Skia) requires this to support ProMotion (120Hz) displays on modern iPhones. Without this key, iOS may throttle the third-party rendering loop to 60Hz, leading to synchronization issues and visible stuttering. The SDK enforces this check to ensure a premium, smooth user experience across all devices.
Last Updated: 2026-04-07