Why Core Bluetooth state restoration never fires
This is a placeholder showing the article format. Replace the body, keep the front matter shape.
Restoration is the single most misunderstood part of Core Bluetooth. Teams set CBCentralManagerOptionRestoreIdentifierKey, see nothing happen, and conclude the feature is broken.
What the option actually does
Setting the identifier registers your central manager with the system. It does not by itself guarantee your process will be relaunched.
let manager = CBCentralManager(
delegate: self,
queue: nil,
options: [CBCentralManagerOptionRestoreIdentifierKey: "com.example.central"]
)
The conditions nobody lists together
- The identifier must be stable across launches. A UUID generated at runtime silently defeats restoration.
centralManager(_:willRestoreState:)must be implemented on the delegate, and it is called beforecentralManagerDidUpdateState(_:).- The app must have been terminated by the system, not by the user swiping it away in the app switcher.
- There must be pending work โ an active scan, a connection, or a connection in progress โ for there to be anything to restore.
If the user force-quits the app, restoration does not happen and will not happen again until the user launches it manually. This is deliberate.
How to tell which condition you are failing
Capture a sysdiagnose while reproducing and look for the relevant subsystem. The logs distinguish these cases clearly, which is more than can be said for the API.