AnyBio
Guides

Scanning & Connecting

BioSDK discovers and connects to BLE wearables through a simple scan-and-connect flow. Discovered peripherals are classified by the biosignals they expose (heart rate, ECG, PPG, EDA, temperature, motion, and others) so your app can pick the right device for the session.

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 standard heart rate peripherals (Bluetooth SIG Heart Rate profile):

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

This is useful in multi-device setups where a primary biosignal device is paired with one or more standard heart rate peripherals (chest straps, wristbands, or other Bluetooth SIG Heart Rate-compatible devices) to round out the signal coverage of a session.

The same scan, connect, and streaming flow applies to any supported wearable: rings, chest straps, watches, patches, optical pulse sensors, glucose monitors, and others. Device-specific behavior is encapsulated in the underlying integration; your app code stays the same across devices.

On this page