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?
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: