Configuration
Configure the Circadify iOS SDK — initialization, callbacks, and measurement options.
Initialization
The simplest way to initialize the SDK is with just your API key:
import CircadifySDK
let sdk = try CircadifySDK(apiKey: "ck_live_your_key_here")swiftFor full control, pass a CircadifyConfig:
let config = CircadifyConfig(
apiKey: "ck_live_your_key_here",
baseUrl: "https://api.circadify.com",
measurementDuration: 30,
debug: false
)
let sdk = try CircadifySDK(config: config)swiftThe Camera
CircadifyCamera owns the single AVCaptureSession that is shared by both the live preview and the measurement. You create one camera, render it with CircadifyCameraPreview(camera:), and hand the same instance to measureVitals(camera:) so the scan records the exact session the user is already looking at.
@State private var camera = CircadifyCamera()swiftBecause the camera and the SDK are decoupled, the preview can be live (and warning the user about framing) before any measurement starts.
CircadifyCameraPreview(camera: camera)
.ignoresSafeArea()swiftFront or back camera
By default CircadifyCamera() uses the front (selfie) camera — the right choice for self-scans, where the user watches the live preview to frame their own face. Pass position: .back for the rear camera instead:
let camera = CircadifyCamera(position: .back)swiftReach for the rear camera when an operator measures another person (or in a kiosk / tripod setup). Its preview is not mirrored, and because the phone's screen no longer acts as a fill light for the subject (it faces away from them), ensure good ambient lighting. Both positions feed the identical on-device pipeline and produce the same measurements — see init(position:) in the method reference.
CircadifyCamera is @MainActor and @Observable. Call try await camera.start() to prompt for permission and bring the session live, and camera.stop() when the view disappears. See Camera & Permissions for the full lifecycle.
Configuration Reference
public struct CircadifyConfig {
public let apiKey: String
public var baseUrl: String
public var measurementDuration: TimeInterval
public var debug: Bool
}swift| Property | Type | Default | Description |
|---|---|---|---|
apiKey | String | — | Required. Your API key (ck_live_*). |
baseUrl | String | "https://api.circadify.com" | API base URL. |
measurementDuration | TimeInterval | 30 | Target capture duration in seconds. |
debug | Bool | false | Print debug logs to the console. |
Callbacks
Progress updates are reported by the SDK, while quality warnings are reported by the camera. Both callbacks are delivered on the main thread.
Progress Updates
Set onProgress on the SDK instance to track a measurement as it runs:
sdk.onProgress = { update in
print("Phase: \(update.phase) — \(Int(update.percent))%")
}swiftpublic struct ProgressUpdate {
public let percent: Double // 0-100
public let phase: Phase // .initializing, .capturing, .uploading, .processing
public let elapsed: TimeInterval
public let remaining: TimeInterval?
}swift| Phase | Description |
|---|---|
.initializing | Setting up camera capture |
.capturing | Capturing the measurement |
.uploading | Uploading the measurement payload |
.processing | Waiting for results |
Quality Warnings
Quality warnings come from the camera, not the SDK. Set onQualityWarning on your CircadifyCamera. Warnings fire while the user is framing themselves in the live preview and during the measurement itself, so you can guide the user before and during a scan.
camera.onQualityWarning = { warning in
print("[\(warning.severity)] \(warning.type): \(warning.message)")
}swiftpublic struct QualityWarning {
public let type: WarningType // .lighting, .motion, .facePosition, .occlusion
public let message: String
public let severity: Severity // .low, .medium, .high
}swift| Warning Type | Trigger |
|---|---|
.lighting | Too dark, too bright, or flickering |
.motion | Excessive movement |
.facePosition | Head turned or tilted too far |
.occlusion | Face partially blocked |
Use these to show guidance in your UI — "Hold still", "Move to better lighting", etc.
Measurement Options
Pass MeasurementOptions to measureVitals(camera:) to provide demographics for improved accuracy:
let options = MeasurementOptions(
demographics: Demographics(age: 35, sex: .male, fitzpatrick: 3)
)
let result = try await sdk.measureVitals(camera: camera, options: options)swift| Field | Type | Notes |
|---|---|---|
age | Int? | User age in years. |
sex | Sex? | .male or .female. Encoded on the wire as "M" / "F". |
fitzpatrick | Int? | Fitzpatrick skin type. Valid values are 1–6. |
Demographics are optional but can improve measurement accuracy when provided.
Next Steps
- Methods — Full method reference
- Camera & Permissions — Handle camera access
- Error Handling — Handle failures gracefully