[Core Bluetooth] The Application which is acting as a CBCentral should automatically connect back with the CBPeripheral in case user has turned OFF the peripheral Device and turned ON the peripheral Device again

  1. Application has specified the bluetooth-central background mode.
  2. Peripheral Device(BLE) is connected to the iPhone.
  3. Application will initiate a request 'retrieveConnectedPeripheralsWithServices' along with list of services to scan for.
  4. Application will receive a list of peripherals connected to the system whose service UUID's match.
  5. From the list of peripherals, application will initiate a request 'connectPeripheral' with the interested peripheral along with the option set to 'CBConnectPeripheralOptionEnableAutoReconnect'. This option is available from iOS 17+.
  6. CBConnectPeripheralOptionEnableAutoReconnect - This option will help in reconnect back to peripheral when peripheral becomes available. (Turn OFF and Turn ON)

How do we achieve the same thing in earlier IOS version

In earlier iOS versions you would request a reconnection directly in your code.

When you get the callback for disconnection you can at that point issue a connectPeripheral() command to the CBPeripheral that has just disconnected.

If you don't have a CBPeripheral, you can also always start a scan in the disconnect callback, and connect after re-discovering the device.

Yes we did try requesting connectPeripheral() command on receiving disconnect callback but there is one use-case where the behaviour was wrong.

  1. Application has issued connectPeripheral() command and is connected with the LE device.
  2. User will go and chose "Forget the device " under bluetooth settings.
  3. Application will receive didDisconnectPeripheral and because of connectPeripheral() command , it was connecting back again to BLE which was NOT the user wanted

Since we saw the above behaviour which will be annoying to user , then we tried scanForPeripheralsWithServices() command with the serviceUUIDs we are interested in. When we use this command is when we saw an issue where our application was not receiving didDiscoverPeripheral() delegate which we were expecting. We did receive didDiscoverPeripheral() delegate the moment we bring our application into foreground

[Core Bluetooth] The Application which is acting as a CBCentral should automatically connect back with the CBPeripheral in case user has turned OFF the peripheral Device and turned ON the peripheral Device again
 
 
Q