Issue with CBConnectPeripheralOptionNotifyOnConnectionKey Not Triggering Alert When Reconnecting in Background

I'm working with CBConnectPeripheralOptionNotifyOnConnectionKey, and my understanding is that it should trigger an alert when a reconnection occurs while the central app is in the background. To test this, I've set up two separate iPhone devices—one acting as the peripheral and the other as the central.

The process I'm using is as follows:

The central app connects to the peripheral app. I then switch to a different app on the central device, which causes the central app to go into the background. I manually disconnect and reconnect Bluetooth on the central device, which should trigger the peripheral app to reestablish the connection. However, despite the central app being in the background, I don't see the expected alert on the central side. The connection reestablishes correctly, but no alert appears.

I would appreciate any insights on what might be causing this issue or if I'm misunderstanding the behavior of CBConnectPeripheralOptionNotifyOnConnectionKey. I'd be happy to provide more specific code or logs if needed.

Thanks in advance! I’m relatively new to Core Bluetooth and feel like I’ve explored most of the options, but I’m still encountering this issue.

To clarify my setup:

The peripheral app has bluetooth-peripheral in its Info.plist. The central app has bluetooth-central in its Info.plist. In my central app, I’m passing the CBConnectPeripheralOptionNotifyOnConnectionKey: true option when calling centralManager.connect after discovering the peripheral:

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {

    
    if let peripheralName = advertisementData[CBAdvertisementDataLocalNameKey] as? String, peripheralName == "test-device-1" {
          // Stop scanning to save power
          centralManager.stopScan()
          
          // Save a reference to the discovered peripheral
        self.discoveredPeripheral = peripheral
        let options: [String: Any] = [
            CBConnectPeripheralOptionNotifyOnConnectionKey: true]
        
          // Connect to the peripheral
        centralManager.connect(discoveredPeripheral!, options: options)
      } else {
        print("No peripheral discovered to connect to.")
    }
}

However, when I move the central app to the background and toggle Bluetooth off/on in Settings, the peripheral reconnects, but I’m not seeing the expected alert. Am I missing any steps, or is there another way to verify this behavior?

CBConnectPeripheralOptionNotifyOnConnectionKey works specifically for apps that cannot be backgrounded. As stated in the documentation

This key is useful for apps that haven’t specified the bluetooth-central background mode and can’t display their own alert

If your app has declared the bluetooth-central background mode, then instead of depending on this notification, you can process the didConnect() callback and if necessary, create your own local notification.


Argun Tekant /  DTS Engineer / Core Technologies

Thank you for your response. To clarify my setup and issue, I have removed the bluetooth-central key from my plist. Here's what I'm doing to test the system alert behavior:

Initially, I connect my central to the peripheral. After the connection, I move the central app to the background. Then, I turn off Bluetooth on the peripheral (which disconnects the central from the peripheral). Afterward, I turn Bluetooth back on in the peripheral (which should trigger it to re-advertise). However, even though the peripheral is re-advertising and the CBConnectPeripheralOptionNotifyOnConnectionKey option is set to true, I'm not seeing the system alert. Could you please help clarify why the alert is not appearing under these circumstances?

Issue with CBConnectPeripheralOptionNotifyOnConnectionKey Not Triggering Alert When Reconnecting in Background
 
 
Q