Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid discovering services and characteristics on a reconnect in CoreBluetooth

I am working on a CoreBluetooth manager app for an iPhone. To be able to reconnect to a previously discovered CBPeripheral, I save the UUID of the peripheral (in CoreData) and then call CBCentralManager's retrievePeripherals:. My didRetrievePeripherals: callback is called and I can connect, etc. So far so good.

Since I am reconnecting to a peripheral that I already know about, I would like to avoid discovering its services and characteristics. So I save the UUIDs of the services and characteristics (again in CoreData, along with the peripheral's UUID) when I first connect.

But I cannot use these UUIDs to read or write the characteristics because the CBPeripheral's readValueForCharacteristic: or writeValueForCharacteristic: take a CBCharacteristic as a parameter, and there is no API to construct a CBCharacteristic instance.

Is there any way to avoid discovering services and characteristics while reconnecting with a previously known peripheral?

like image 927
mezulu Avatar asked Oct 24 '12 16:10

mezulu


1 Answers

Mezulu, you want to use an encrypted/paired link – then iOS will do the caching for you. See my answer here.

like image 131
William henderson Avatar answered Sep 23 '22 19:09

William henderson