2
votes

I'm making an iOS app that uses Core Bluetooth and periodically checks to see if the peripherals are still around. My problem is that when I shut off the advertising device (even shut off the bluetooth entirely), my central device still returns the CBPeripheral object when I call retrievePeripheralsWithIdentifiers. I need it to accurately NOT return this the peripheral once it is no longer advertising. Thanks in advance!

1

1 Answers

2
votes

retrievePeripheralsWithIdentifiers looks into the Core Bluetooth database to see if it can find an peripheral with the specified identifier, regardless of whether advertisements from that peripheral are currently visible. This allows you to issue a connect to a peripheral that has been seen before and may be seen again (The "lock" scenario described in the Core Bluetooth Programming Guide is one example where you could use this).

To see if a peripheral is advertising or not you need to call scanForPeripheralsWithServices, specifying YES for CBCentralManagerScanOptionAllowDuplicatesKey and keep your own table of visible peripherals, ageing them out when you haven't seen an advertisement for some period.