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 units—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. Nevertheless, regardless of the central app being within the background, I do not see the anticipated alert on the central facet. The connection reestablishes appropriately, however no alert seems.
I might recognize any insights on what could be inflicting this subject or if I am misunderstanding the conduct of CBConnectPeripheralOptionNotifyOnConnectionKey
. I would be pleased to supply 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 subject.
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 avoid wasting 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 information.plists