Gate CoreBluetooth state restoration#255
Conversation
There was a problem hiding this comment.
Code Review
This pull request gates CoreBluetooth state restoration on iOS behind the bluetooth-central background mode. If the mode is not declared in the host app's Info.plist, CBCentralManager is created lazily on the first BLE API call and state restoration is disabled, preventing crashes at launch for apps that do not use this background mode. The review feedback suggests optimizing the hasBluetoothCentralBackgroundMode check by caching its value as a static stored property instead of evaluating it dynamically on every access.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…swift Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes iOS startup crashes and unintended Bluetooth permission prompts introduced by eager CBCentralManager state restoration by making state restoration (and eager manager creation) opt-in based on the host app declaring the bluetooth-central background mode. It aligns the implementation with the expected “opt-in via Info.plist” behavior described in issue #254.
Changes:
- iOS: Detect
UIBackgroundModes→bluetooth-centraland only passCBCentralManagerOptionRestoreIdentifierKey/ eagerly instantiateCBCentralManagerwhen present. - Docs: Update README state-restoration section to explicitly describe the opt-in behavior and lazy creation otherwise.
- Release hygiene: Bump version to
2.0.4and add a changelog entry describing the fix.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
darwin/universal_ble/Sources/universal_ble/UniversalBlePlugin.swift |
Gates state restoration and the restore identifier option behind an Info.plist background-mode check to avoid launch-time crash/prompt. |
README.md |
Updates iOS state restoration documentation to match the new opt-in + lazy manager behavior. |
CHANGELOG.md |
Adds 2.0.4 entry describing the iOS gating change. |
pubspec.yaml |
Bumps package version from 2.0.3 to 2.0.4. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6646c91 to
98999bc
Compare
… creation until Bluetooth permission is granted
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fixes #254