ios – 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.

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.")
    }
}

Also to note I’ve tried both with bluetooth-peripheral and/or bluetooth-central in the info.plists


Discover more from TrendyShopToBuy

Subscribe to get the latest posts sent to your email.

Latest articles

spot_imgspot_img

Related articles

Leave a Reply

spot_imgspot_img

Discover more from TrendyShopToBuy

Subscribe now to keep reading and get access to the full archive.

Continue reading

Subscribe