CoreBluetooth State Restoration not available when launching in the foreground?

We recently added CoreBluetooth State Preservation and Restoration to our BLE device-connected application. It works great when the peripheral triggers State Restoration, bringing the app to life in the background and providing the still connected peripheral in the willRestoreState: dictionary. But if the user decides to launch the application by touching the app icon before they've interacted with the peripheral, willRestoreState: isn't called even if the state was preserved when the app was killed by iOS. If I call retrieveConnectedPeripherals withServices: on the CBCentralManager that I initialize with the same CBCentralManagerOptionRestoreIdentifierKey I do get the previously connected peripheral returned, but it's in the disconnected state. While I can connect to it easily, the process has caused a brief disconnection from the peripheral which is indicated to the user in our case - causing some confusion about the connection status.


Is there no way to restore the preserved CBCentralManager if the app is launched normally?


I watched system logs for both cases and it certainly seems like this is expected behavior:


On a proper restoration from interacting with the peripheral:

default 14:08:45.689700 -0700 BTServer State of application “com.appName” is now "unknown"

default 14:08:45.692737 -0700 BTServer Application "com.appName" has been terminated

default 14:08:45.698884 -0700 BTServer Session "com.appName-central-468-0" will be persisted, as it was performing long-term action(s): connecting

default 14:08:49.324558 -0700 BTServer LaunchServices observer: Will install <private>

error 14:08:51.102749 -0700 BTServer <private>

default 14:08:51.102874 -0700 BTServer <private>:WorkspaceObserver:0:Success:<private>

default 14:09:49.709264 -0700 BTServer ✞✟✝ Resurrecting zombie application "com.appName" ✝✟✞

default 14:09:49.712950 -0700 BTServer Attempting to launch application "com.appName" with userInfo: <private>

error 14:09:49.746239 -0700 BTServer Unable to create process assertion for application "com.appName"

default 14:09:49.793363 -0700 SpringBoard Received trusted open application request for "com.appName" from <FBProcess: 0x1702f1600; BTServer; pid: 64>.

default 14:09:50.022635 -0700 SpringBoard Executing suspended-activation immediately: OpenApplication(com.appName)ForRequester(BTServer.64)

default 14:09:54.861666 -0700 BTServer Received XPC message "CBMsgIdCheckIn" from session ""

default 14:09:54.862110 -0700 BTServer Received XPC check-in from session "com.appName-central-474-0"

default 14:09:54.862504 -0700 BTServer Restoring zombie'd central session "com.appName-central-468-0" for application "com.appName"

default 14:09:54.863754 -0700 BTServer Sending XPC message "CBMsgIdRestoringCentralManagerState" to session "com.appName-central-474-0"

default 14:09:54.864092 -0700 BTServer Sending 'state updated' event with state "On" to session "com.appName-central-474-0"

default 14:09:54.864721 -0700 BTServer Sending XPC message "CBMsgIdStateUpdated" to session "com.appName-central-474-0"


On an app launch from home screen icon:

default 13:51:56.521239 -0700 BTServer State of application "com.appName" is now "unknown"

default 13:51:56.522394 -0700 BTServer Application "com.appName" has been terminated

default 13:51:56.534532 -0700 BTServer Session "com.appName-central-465-0" will be persisted, as it was performing long-term action(s): connecting

default 13:52:06.941283 -0700 BTServer Application "com.appName" is now at pid 468, with state "foreground-running"

default 13:52:07.203196 -0700 BTServer Received XPC message "CBMsgIdCheckIn" from session ""

default 13:52:07.203515 -0700 BTServer Received XPC check-in from session "com.appName-central-468-0"

default 13:52:07.203608 -0700 BTServer Application "com.appName" has been re-launched manually following a jetsam - purging any persisted sessions...

default 13:52:07.203756 -0700 BTServer Killing session "com.appName-central-465-0" (ID: "CoreBluetoothManager")

default 13:52:07.204031 -0700 BTServer Unregistering central session "com.appName-central-465-0"

default 13:52:07.204260 -0700 BTServer Unregistering session "com.appName-central-465-0"

default 13:52:07.204723 -0700 BTServer Disabling notifications/indications on client configuration descriptor at handle 0x0027 on device "<private>"

default 13:52:07.204971 -0700 BTServer Disconnecting unused device “XXX-XXX-XXX-XXX”

default 13:52:07.205228 -0700 BTServer Sending 'session detached' event for session "com.appName-central-465-0"

default 13:52:07.205437 -0700 BTServer Sending 'session attached' event for session "com.appName-central-468-0"

default 13:52:07.205703 -0700 BTServer Registering central session "com.appName-central-468-0" with backgrounding: on, persistence: on, restoreID: "CoreBluetoothManager"

default 13:52:07.205821 -0700 BTServer Sending 'state updated' event with state "On" to session "com.appName-central-468-0"

default 13:52:07.206049 -0700 BTServer Sending XPC message "CBMsgIdStateUpdated" to session "com.appName-central-468-0"

CoreBluetooth State Restoration not available when launching in the foreground?
 
 
Q