1

I want my App to either be connected or attempting to connect to a known peripheral retrieved with -retrievePeripheralsWithIdentifiers or -retrieveConnectedPeripheralsWithServices. When the peripheral disconnects, re-connection should be attempted. In this way, the App receives notifications from the peripheral and presents local push notifications. This works fine when the App is in the foreground or background and still running.

In the background, if the App is killed for whatever reason (user closes, memory low) then the system disconnects the peripheral, but the App does not get notified of disconnection, so cannot reconnect automatically to continue receiving notifications. How can I attempt reconnection when the App is quit?

Nick
  • 3,958
  • 4
  • 32
  • 47

1 Answers1

0
  1. Enable the bluetooth-central background mode

  2. Use the CBCentralManagerOptionRestoreIdentifierKey option supplying a unique identifier when instantiating your CBCentralManager

  3. Implement the - (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)state delegate method.

3.1 Get an array of restorable peripherals using NSArray *peripherals = state[CBCentralManagerRestoredStatePeripheralsKey]

3.2 Call the connectPeripheral method of your CBCentralManager supplying each peripheral to restore

Note :- Read more of the details in the Core Bluetooth Programming Guide

Balaji Gupta
  • 33
  • 1
  • 12
  • I have already done all of this, but the problem is the App has been quit and is not notified the peripheral has been disconnected, so the process is not started again in order to re-initiate the connection – Nick Jan 01 '16 at 10:29
  • 1
    Do you mean the use has killed the app in the task switcher? Because in this case the app will not be automatically relaunched. – Rhythmic Fistman Jan 01 '16 at 10:34