Prerequisites

Your app project must declare the required permission usage. This applies equally to both native, Flutter and React Native app projects.

Bluetooth devices

Choose Device Model

The SDK provides a list of supported Bluetooth devices. Select the matching instance to prepare for scanning.

import VitalDevices

let devicesManager = DevicesManager()

/// Get the brands
let brands = DevicesManager.brands()

/// Each brand has devices
let devices = DevicesManager.devices(for: brands[0])

Scanning for devices

First you have to scan for one of the supported devices.

let cancellable = devicesManager
  .search(for: state.device)
  .sink { scannedDevice in
    print("Discovered: \(scannedDevice)")
  }

// Stop scanning
cancellable.cancel()

Depending on the type of device you are connecting to, you will have to call different methods to connect to it.

Blood Pressure Monitor

let scannedDevice: ScannedDevice
let reader = deviceManager.bloodPressureReader(for: scannedDevice)

reader.read(device: scannedDevice).sink { samples in
  print("Read samples: \(samples)")
}

Glucose Meter

let scannedDevice: ScannedDevice
let reader = deviceManager.glucoseMeter(for: scannedDevice)

reader.read(device: scannedDevice).sink { samples in
  print("Read samples: \(samples)")
}

After you have received samples depending on the type of device you might need to star scanning again to receive the next set of samples.

Freestyle Libre 1

Readings taken with the SDK are not guaranteed to match the official Freestyle Libre app. This mismatch happens due to the algorithm difference used by us, compared to the official Freestyle Libre.

We currently support Libre 1 sensors via NFC readings. Please make sure you add NFC capabilities in your app:

Also add the key NFCReaderUsageDescription in your info.plist. This key should explain why your app needs to use NFC.

To use the reader:

let reader = Libre1Reader(
    readingMessage: "Ready for reading",
    errorMessage: "Failed reading from sensor",
    completionMessage: "Completed successfully!",
    queue: mainQueue
)

let reading = try await reader.read()

read() returns a result object with two fields:

  1. the sensor information; and
  2. a list of glucose samples.

Posting device samples to Vital

Vital Devices SDK does not automatically send the samples back to Vital data store.

To ensure that data are available, you would need to post the samples through the SDK:

import VitalCore

let samples: [QuantitySample]

try await VitalClient.shared.timeSeries.post(
  .glucose(samples),
  stage: .daily,
  provider: .libre,
  timeZone: .current
)