Skip to main content

Background Mode

BioSDK supports continuous biosignal streaming while your app is in the background. This is essential for overnight monitoring, extended research sessions, and clinical data capture.

Setup

Ensure your Info.plist includes the required background modes (see Installation):

<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>processing</string>
<string>remote-notification</string>
</array>

<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>io.anybio.upload</string>
<string>io.anybio.session.maintenance</string>
</array>

AppDelegate Integration

For reliable background BLE operation, initialize the BLE subsystem early in your app's lifecycle:

class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Initialize BLE manager early for state restoration
_ = BioBLEManager.shared
return true
}

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Check if launched for BLE state restoration
if let centralIds = launchOptions?[.bluetoothCentrals] as? [String] {
// App was relaunched by the system to restore BLE connections
}
return true
}
}

Background Recovery

If your app is terminated by the system (e.g., due to memory pressure), the SDK can restore its state on relaunch:

// In your AppDelegate, restore SDK state on background launch
if let sdk = try? BioSDKClient.restoreIfNeeded(isBackground: true) {
// SDK restored with previous session context
self.sdk = sdk
}

The SDK persists session state, device mappings, and buffered data across app terminations. Unuploaded biosignal data is preserved and will resume uploading when connectivity is restored.

Idle Timer

During active streaming, the SDK disables the device idle timer to prevent the screen from dimming. This is automatically managed — the idle timer is restored when streaming stops.

Best Practices

  • Initialize BioBLEManager.shared in willFinishLaunchingWithOptions — this is required by CoreBluetooth for state restoration
  • Use streaming profiles with auto-reconnect for unattended sessions — the SDK will reconnect and resume streaming if the BLE connection drops
  • Enable auto-stream on devices that should resume streaming on reconnection
  • Test on real devices — the iOS Simulator does not support BLE background modes