Skip to main content

Scanning & Connecting

BioSDK discovers and connects to BLE wearables through a simple scan-and-connect flow. Devices are automatically classified as rings, heart rate monitors, or other peripherals.

Scanning for Devices

// Start BLE scanning
sdk.startScan()

// Check if currently scanning
if sdk.isScanning {
print("Scanning...")
}

// Stop scanning (saves battery)
sdk.stopScan()

Discovered devices are emitted as .lifecycle(.discovered(device)) events and accumulated in sdk.discoveredDevices:

sdk.events.sink { event in
if case .lifecycle(.discovered(let device)) = event {
print("Found: \(device.name) (\(device.id))")
}
}

Connecting

let device = sdk.discoveredDevices.first!
sdk.connect(device)

Monitor connection progress through device state events:

sdk.events.sink { event in
if case .deviceState(let device, let connection, let stream) = event {
switch connection {
case .connecting:
print("\(device.name) connecting...")
case .discoveringServices:
print("\(device.name) discovering services...")
case .ready:
print("\(device.name) ready to stream!")
case .disconnected:
print("\(device.name) disconnected")
case .failed:
print("\(device.name) connection failed")
case .discovered:
break
}
}
}

Connection States

Each device progresses through these connection states:

.discovered → .connecting → .discoveringServices → .ready
→ .failed
→ .disconnected
StateDescription
.discoveredDevice found during scanning, not yet connected
.connectingBLE connection in progress
.discoveringServicesConnected, discovering BLE services and characteristics
.readyFully connected, services discovered — ready to stream
.failedConnection attempt failed
.disconnectedPreviously connected, now disconnected

Disconnecting

// Disconnect a specific device
sdk.disconnect(device)

// Disconnect all connected devices
sdk.disconnectAll()

Device Model

The BioDevice type represents a discovered or connected peripheral:

public struct BioDevice {
public let id: UUID // CoreBluetooth peripheral identifier
public let name: String // Advertised device name
}

Querying Device State

Check a device's current connection and streaming state at any time:

if let (connection, stream) = sdk.deviceSessionState(deviceId: device.id) {
print("Connection: \(connection), Stream: \(stream)")
}

Heart Rate Monitor Auto-Connect

For apps that want to automatically connect to nearby heart rate monitors:

// Enable auto-connect for HRM peripherals
BioBLEManager.shared.enableAutoConnectHRM(true, maxConnections: 3)

This is useful for multi-device setups where a primary ring is supplemented with one or more standard HRM chest straps or wristbands.