iOS CBPeripheralManager state restoration broken on iOS 11

Originator:kane.cheshire
Number:rdar://34568166 Date Originated:September 21 2017
Status:Closed Resolved:
Product:iOS SDK Product Version:iOS 11
Classification:Serious bug Reproducible:Always
 
Summary:
CBPeripheralManagers no longer provide the restored services (and therefore no restored characteristics or subscribed centrals) in the delegate method `willRestoreState`.

This is a huge, huge issue because centrals still connected to the iOS device acting as a the CBPeripheralManager have no idea that the iOS device cannot communicate, and all write requests from the CBCentral fail on the central side with no callbacks at all on the iOS CBPeripheralManager side.

This issue is easily reproducible and I've attached two projects, one for iOS with a simple CBPeripheralManager setup, and one for macOS with a simple CBCentralManager setup.

Steps to Reproduce:
1. Open the iOS and macOS projects bundled with this project on iOS 11 and macOS High Sierra. It must be macOS High Sierra due to a different bug with Xcode 9 and Core Bluetooth (radar 34428271)
2. Run the iOS project on a physical device running the release version of iOS 11
3. Run the macOS project so that it connects to the iOS device and writes a value (you will see output of this in the console)
4. DO NOT TURN OFF BLUETOOTH OR STOP THE MACOS APP
5. Re-run the iOS app and observe that the CBPeripheralManagerDelegate callback to `willRestoreState` is called, but is _not_ prodded with the services that it were currently published at the time of restoration. Also observe that on the macOS side, there is no output to say that the device disconnected.
6. Disable and re-enable Bluetooth on macOS to force a disconnection and automatically initiate a reconnection when Bluetooth is turned back on.
7. Observe that where the macOS app could previously write to the connected peripheral, it no longer can with "unknown error" outputs.

Expected Results:
The iOS app should only call `willRestoreState` while centrals are still connected if the services are going to be provided in the callback, as per the documentation.

Actual Results:
The iOS does not provide the services in the callback.

Version/Build:
iOS 11 GM
macOS High Sierra

Configuration:

iPhone 7 Plus (Black)
MacBook 12" (Early 2015)

Comments

Hey Kane, try out iOS 11.2 beta 1, it's looking like they're working the fix in. Hopefully won't break in future beta releases.

I filed a duplicate bug and got back a status update saying this is a duplicate of another bug, 34243923. No other insight but the bug is currently open and not fixed as of today (iOS 11.0.3/11.1 Beta 5).


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!