Unable to trigger state restoration code for BLE on iOS : <p>I am trying to get my app to respond relaunch into the background is response to discovering an advertising peripheral.</p>

<p>The following code currently works in my app (in foreground + background, even after many hours of being backgrounded):</p>

<pre><code>[self.centralManager scanForPeripheralsWithServices:self.services options:nil];
</code></pre>

<p>Generally, my app does not have any pending connection requests, as I want to scan for new advertisements in the background. The following documentation leads me to believe that this is still possible:</p>

<blockquote>
  <p><em>it is important to keep in mind that the app will be relaunched and restored if and only if it is pending on a specific Bluetooth event or action (like scanning, connecting, or a subscribed notification characteristic), and this event has occurred.</em> (from <a href="https://developer.apple.com/library/content/qa/qa1962/_index.html" rel="noreferrer">https://developer.apple.com/library/content/qa/qa1962/_index.html</a>)</p>
</blockquote>

<p>and</p>

<blockquote>
  <p><em>The system keeps track of...The services the central manager was scanning for (and any scan options specified when the scan started)</em> (from <a href="https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html" rel="noreferrer">https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html</a>)</p>
</blockquote>

<h1>Implementation</h1>

<p>I am following the steps outlined in this last link ^ under the section "Adding Support for State Preservation and Restoration", by doing the following things:</p>

<ol>
<li><p>Instantiating the central manager as directed:</p>

<p>self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:@{ CBCentralManagerOptionRestoreIdentifierKey:@"myCentralManagerIdentifier" }];</p></li>
<li><p>Reinstantiate Your Central and Peripheral Managers</p></li>
</ol>

<p>Here I've actually not done anything else, since <code>didFinishLaunchingWithOptions</code> is called and the central will be reinitialized with the same identifier. (Is there something else to be done here that I'm missing?)</p>

<ol start="3">
<li><p>Implementing the restoration function:</p>

<p>(void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)state {
  // Breakpoint set here but never reached...
  NSLog(@"...");
}</p></li>
</ol>

<h1>How I am testing state preservation / restoration</h1>

<p>I have set a breakpoint in the restore function (from step 3) and also inserted an <code>NSLog</code>.</p>

<p>By clicking "stop", as suggested in <a href="https://stackoverflow.com/questions/33130124/how-to-trigger-core-bluetooth-state-preservation-and-restoration/33137848#33137848">How to trigger Core Bluetooth state preservation and restoration</a>, I was hoping that I could trigger the code by advertising with my peripheral as I would do normally (this discovery/connection flow is working perfectly when the app is running in the background). But nothing really happens that I can tell.</p>

<p>My general question is: why is the breakpoint not triggered / NSLogs not printed? Is there a preferred way to debug the restoration feature?</p>

<p>Finally, as a sanity check, am I reading the docs correctly that discovery of an advertising peripheral should trigger the re-launch of the app into the background for the app to handle?</p>
