I got a problem since the iOS 8 update, right now my app is connected to a BLE device and periodically reads the RSSI thanks to a timer and the ReadRSSI
method.
I recently ran into this issue and I had multiple issues that was causing it. Here's the solutions in checklist fashion, from simplest to most complex:
CBCentralManager
won't hold a strong reference to the peripheral
, you need to keep it yourself.peripheral.delegate
.peripheral(peripheral:didReadRSSI:error:)
and not the old one.readRSSI
for devices that are connected to your central, so:
[CBCentralManagerScanOptionAllowDuplicatesKey : true]
when doing scanForPeripheralsWithServices(_:options:)
. As seen in this answer.central.retrieveConnectedPeripheralsWithServices
. this method returns "connected" devices, but the readRSSI
nor service discovery work until you actually call connectPeripheral(_:options:)
on them, so even though they are connected to the iPhone/iPad/AppleWatch, they are not connected to your central, very annoying.This last one was the big gotcha for me, I was hoping to "pick the closest" connected or discovered device, but couldn't keep the RSSI updated on them. Documentation doesn't say anything either.
What I ended up doing, was to build a big dictionary with all the devices indexed by [UUID : Device]
(device being a wrapper for the CBPeripheral
). Devices added via discovery get their RSSI updated via de discover method, and the connected ones via a GCD timer on the bluetooth queue that calls readRSSI
and update their own RSSI reading.