CoreBluetooth: What is the lifetime of unique UUID

2019-01-11 12:04发布

问题:

Following off of this question,

After connecting to a peripheral, I can retrieve its CFUUIDRef, which is unique, and can use it to reconnect via retrievePeripherals. However, I have found that I can not use it to reconnect after closing the application.

Is the unique UUID generated after a connection only valid for the lifetime of the application or are we supposed to be able to save it for later use? I am trying to have my application remember one particular peripheral, but besides peripheral.UUID, I don't know of any other unique identifiers.

回答1:

Long story short, YES you can use the UUID to reconnect to the same device even after you close the application (in exactly the way you say). I've done it with every single one of my corebluetooth apps and I guarantee you 100% that's exactly how you should do it.

I assume however, that you are not pairing with peripheral?? That's a big problem right there. You need to actually establish the pairing request and get the peripheral to show up in the bluetooth table. The UUID will then be solidified with the iOS device and will remain until you flush the Network Settings of the iOS device. (This of course being dependent on ble chipset..While this stands true for some of the most common devices in the industry, it can be accomplished without it though. Indicate your chipset and I'll confirm if I know one way or the other)

The other possibility is that your BLE device has a firmware problem, wherein after you disconnect, it forces itself into advertising mode or something. This will also mess with your ability to reconnect. Let me know if you have any questions!