BioSDKClient
Main SDK entry point — initialization, scanning, streaming, session management, and device operations.
The primary entry point for all BioSDK operations. Manages device scanning, connections, streaming sessions, image uploads, and more.
public final class BioSDKClientSDK Version
public static let sdkVersion: StringInitialization
Configuration
public struct Configuration: Equatable {
public let environment: Environment
public let organizationKey: String?
public let projectKey: String
public init(
environment: Environment = .auto,
organizationKey: String? = nil,
projectKey: String
)
public static func auto(
organizationKey: String? = nil,
projectKey: String
) -> Configuration
}Environment
public enum Environment: Equatable {
case auto
case production
}| Case | Description |
|---|---|
.auto | Resolves the environment from Environment.plist at runtime |
.production | Always connects to https://api.anybio.io |
Creating an Instance
// Synchronous convenience initializer
public convenience init(configuration: Configuration)
// Async initializer — performs bootstrap (loads supported devices, org config)
public static func initialize(configuration: Configuration) async throws -> BioSDKClient
// Restore a previously persisted session (e.g., after background wake or app relaunch)
public static func restoreIfNeeded(isBackground: Bool = true) throws -> BioSDKClient?Example:
let sdk = try await BioSDKClient.initialize(
configuration: .auto(projectKey: "my-project")
)Properties
| Property | Type | Description |
|---|---|---|
ble | BioBLEManager | Direct access to the BLE manager |
live | BioLiveStore | Observable data store for real-time UI |
notifications | BioNotificationsStore | Push notification store |
session | SessionManager | Session state manager |
events | PassthroughSubject<BioEvent, Never> | Combine publisher for all SDK events |
sessionContext | BioSessionContext | Current session context (@Published) |
oauth | OAuthManager? | OAuth manager (nil until configured) |
currentSessionId | String? | Active backend session ID |
conflictingSessionId | String? | Session ID from a 409 conflict |
isScanning | Bool | Whether BLE scanning is active |
discoveredDevices | [BioDevice] | Devices found during the current scan |
clientInfo | [String: String] | SDK version and device metadata sent with API calls |
Scanning & Connecting
// Start scanning for BLE devices
public func startScan()
// Stop scanning
public func stopScan()
// Connect to a discovered device
public func connect(_ device: BioDevice)
// Disconnect a specific device
public func disconnect(_ device: BioDevice)
// Disconnect all connected devices
public func disconnectAll()Streaming Control
// Start streaming for a specific device (by BLE UUID)
public func startStreaming(deviceId: UUID)
// Stop streaming for a specific device
public func stopStreaming(deviceId: UUID)
// Enable/disable auto-streaming on connect for a device
public func setAutoStream(deviceId: UUID, enabled: Bool)
// Query current connection + stream state for a device
public func deviceSessionState(deviceId: UUID) -> (BioConnectionState, BioStreamState)?
// Check if auto-stream is enabled for a device
public func autoStreamEnabled(deviceId: UUID) -> Bool?Session Management
// Enable or disable session mode
public func setSessionMode(enabled: Bool)
// Start a backend session for a user (with completion handler)
public func startStreaming(
for xUser: String,
completion: @escaping (Result<String, SessionStartDisposition>) -> Void
)
// Start a backend session (fire-and-forget)
public func startStreaming(for xUser: String)
// Start only the backend session (without triggering BLE streaming)
public func startBackendSession(
for xUser: String,
completion: @escaping (Result<String, SessionStartDisposition>) -> Void
)
// Stop all streaming and end the backend session
public func stopStreaming()
// End the active session without stopping BLE connections
public func endActiveSession()
// Check if the backend has an active session for the current user
public func checkForActiveSession() async throws -> Bool
// Detect an orphaned session from a previous app launch
public func detectOrphanedSession() async throws -> OrphanedSessionInfo?
// Resume an orphaned session
public func resumeOrphanedSession() async throws -> Bool
// End an orphaned session
public func endOrphanedSession()Conflict Resolution
When a session start returns HTTP 409 (an active session already exists), the SDK emits a .session(.conflict(...)) event. Use these methods to resolve:
// Resume the existing conflicting session
public func resumeConflictingSession()
// End the conflicting session and start a new one
public func endConflictingAndStartNew()
// Cancel the pending conflict without action
public func cancelPendingConflict()SessionStartDisposition
Returned as the error type when starting a session:
public enum SessionStartDisposition: Error, Equatable {
case new // New session created
case resumed // Existing session resumed
case conflict(activeId: String, startedAt: Date?) // 409 conflict
}Streaming Profiles
// Activate a named streaming profile on a device
public func activateStreamingProfile(deviceId: UUID, profileName: String) async throws
// Deactivate the current streaming profile
public func deactivateStreamingProfile(deviceId: UUID, executeStop: Bool = true)
// List available streaming profiles for a device
public func getStreamingProfiles(deviceId: UUID) -> [StreamingProfileUI]
// Get the currently active profile name
public func activeStreamingProfile(deviceId: UUID) -> String?Device Operations
// Get available operations for a device
public func getDeviceOperations(deviceId: UUID) -> [DeviceOperationUI]
// Execute a named operation (e.g., "start_ecg", "calibrate")
public func executeOperation(deviceId: UUID, operationName: String) async throwsBuffer & Upload Monitoring
Advanced buffer and upload monitoring APIs are available as part of the AnyBio Enterprise plan. Contact us to learn more about enabling these capabilities for your organization.
Image Upload
// Upload a UIImage for a user
public func uploadImage(_ image: UIImage, userId: UUID) async throws
// Upload raw image data with a MIME type
public func uploadImageData(
_ data: Data,
mimeType: String,
userId: UUID,
deviceId: String? = nil
) async throwsSee the Images API reference for query and response types.
User Management
// Create a new external user
public func createXUser(
identifier: String,
name: String
) async throws -> XUserHTTPClient.XUserResponse
// Get or create an external user (idempotent)
public func getOrCreateXUser(
identifier: String,
name: String
) async throws -> XUserHTTPClient.XUserResponse
// Look up an existing external user
public func getXUser(identifier: String) async throws -> XUserHTTPClient.XUserResponseSee the Users API reference for the BioXUser response type.
OAuth
// Configure OAuth with a callback URL scheme
public func configureOAuth(
callbackURLScheme: String,
userTokenProvider: (() async -> String?)? = nil
)
// Connect an OAuth provider (opens ASWebAuthenticationSession)
public func connectOAuthProvider(
_ provider: String,
xuserId: String,
presentationContextProvider: ASWebAuthenticationPresentationContextProviding
) async throws
// Check if a provider is connected
public func isOAuthProviderConnected(_ provider: String) -> Bool
// Disconnect a provider
public func disconnectOAuthProvider(_ provider: String)See the OAuth API reference for full type details.
Diagnostic Logging
Diagnostic logging and BLE packet capture APIs are available as part of the AnyBio Enterprise plan. Contact us to learn more about enabling these capabilities for your organization.