From 7a1adee3b92adfa3dbd02e909cdf7a81f6cbbe07 Mon Sep 17 00:00:00 2001 From: Eric Watson Date: Fri, 10 Feb 2023 11:03:32 -0600 Subject: [PATCH] Preserve advertisements for retrieved peripherals Fixes a bug where advertisement data would be dropped for peripherals that were retrieved from the system. --- BlueCapKit/Central/CentralManager.swift | 1 + BlueCapKit/Central/Peripheral.swift | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/BlueCapKit/Central/CentralManager.swift b/BlueCapKit/Central/CentralManager.swift index 1c9dd9a8..2e62d79b 100644 --- a/BlueCapKit/Central/CentralManager.swift +++ b/BlueCapKit/Central/CentralManager.swift @@ -323,6 +323,7 @@ public class CentralManager : NSObject, CBCentralManagerDelegate { bcPeripheral = discoveredPeripheral if bcPeripheral.cbPeripheral === peripheral { bcPeripheral._RSSI = RSSI.intValue + bcPeripheral.updateAdvertisements(advertisementData) afterPeripheralDiscoveredPromise?.success(bcPeripheral) } else { afterPeripheralDiscoveredPromise?.failure(CentralManagerError.invalidPeripheral) diff --git a/BlueCapKit/Central/Peripheral.swift b/BlueCapKit/Central/Peripheral.swift index 0ba31798..d05007ef 100644 --- a/BlueCapKit/Central/Peripheral.swift +++ b/BlueCapKit/Central/Peripheral.swift @@ -209,6 +209,12 @@ public class Peripheral: NSObject, CBPeripheralDelegate { } } + // MARK: Advertisements + + public func updateAdvertisements(_ advertisementData: [String: Any]) { + self.advertisements = PeripheralAdvertisements(advertisements: advertisementData) + } + // MARK: RSSI public func readRSSI() -> Future {