I'm developing the CBCentral iOS app that is not supposed to keep persistent connection to the peripheral devices but still need to periodically read data from them.
Most of the peripherals now are iPhones that implement CBPeripheral part.
Central application always run in a foreground and has CBCentralManagerScanOptionAllowDuplicatesKey set to NO.
The flow is the following:
1. Timer tick(e.g. 1 minute)
2. Restart scan
3. Discover peripheral
4. If it's new peripheral then retain it OR if it's already retained peripheral and it's time to update the value
then connect -> discover services -> discover characterictics -> write to characterictic -> receive characterisctic value updates -> disconnect.
At some point previously discovered peripheral device is being discovered as a new instance of CBPeripheral, I think it happens when peripheral changes it's mac address.
For this newly discovered CBPeripheral instance communication flow gets stuck on either service discovery, characteristics discovery, writing to characterictics or receiving characterisctic value updates.
I'm 100% sure that previous CBPeripheral instance of this device is not connected at that moment.
Similar issue happens if I release CBPeripheral instance right after I receive centralManager:didDisconnectPeripheral:error: event for it. The same instance is discovered later on next timer tick and communication flow stucks on service discovery.
My questions are:
1) What is the best practice of handling periodical connections(if there is any)?
2) How to handle discovery of previously discovered device as a new instance of CBPeripheral?