9.5 C
New York
Tuesday, March 11, 2025

ios – Challenge with CBConnectPeripheralOptionNotifyOnConnectionKey Not Triggering Alert When Reconnecting in Background


I am working with CBConnectPeripheralOptionNotifyOnConnectionKey, and my understanding is that it ought to set off an alert when a reconnection happens whereas the central app is within the background. To check this, I’ve arrange two separate iPhone gadgets—one performing because the peripheral and the opposite because the central.
The method I am utilizing is as follows:
The central app connects to the peripheral app. I then swap to a distinct app on the central system, which causes the central app to enter the background. I manually disconnect and reconnect Bluetooth on the central system, which ought to set off the peripheral app to reestablish the connection. Nonetheless, regardless of the central app being within the background, I do not see the anticipated alert on the central facet. The connection reestablishes accurately, however no alert seems.
I might respect any insights on what could be inflicting this situation or if I am misunderstanding the conduct of CBConnectPeripheralOptionNotifyOnConnectionKey. I might be glad to offer extra particular code or logs if wanted.
Thanks upfront! I’m comparatively new to Core Bluetooth and really feel like I’ve explored many of the choices, however I’m nonetheless encountering this situation.

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

    
    if let peripheralName = advertisementData[CBAdvertisementDataLocalNameKey] as? String, peripheralName == "test-device-1" {
          // Cease scanning to save lots of energy
          centralManager.stopScan()
          
          // Save a reference to the found peripheral
        self.discoveredPeripheral = peripheral
        let choices: [String: Any] = [
            CBConnectPeripheralOptionNotifyOnConnectionKey: true]
        
          // Connect with the peripheral
        centralManager.join(discoveredPeripheral!, choices: choices)
      } else {
        print("No peripheral found to hook up with.")
    }
}

Additionally to notice I’ve tried each with bluetooth-peripheral and/or bluetooth-central within the data.plists

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles