15

Following off of this question:
Corebluetooth, How to get a unique UUID?

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
loadedion
  • 2,217
  • 19
  • 41

1 Answers1

16

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 assume however, that you are not actually 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.

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!

Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75
  • Ah, pairing is exactly the issue that I need to fix. My main problem right now is that I'm developing without a complete BLE module to work with. So can you tell me what, if anything must be done on the app/iOS side when pairing? I've asked this question before, but the answers were hazy. I'll find out the chipset and get back to you on that. Thanks! – loadedion Jul 10 '13 at 17:16
  • The iOS side really is dependent on the chipset (also firmware)..so lets talk after you find that out..dont wanna give you bad intel – Tommy Devoy Jul 10 '13 at 17:22
  • 1
    @TommyDevoy Just to clarify: Is pairing done when we get to the 'didConnectPeripheral' function and go further to discover services or is there some other procedure to be followed to pair to a particular device? – Jobs Jan 19 '16 at 11:18
  • @Jobs as far as I know there is no event indicating, that the device has become paired. However you can observer for UIApplicationDidBecomeActiveNotification to determine when user closes 'pairing' popup and then you can call retrieveConnectedPeripheralsWithServices to get list of connected devices to the system and check if yours is there. You can also discover services without any knowledge if it's paired or not. If pairing is required then system will show a proper alert. – Wojciech Kulik Dec 07 '16 at 09:50
  • @TommyDevoy what do you do when the peripheral changes its peripheral.uuid? How can you reconnect to the same device if its identifier has changed? – Changerrs May 08 '18 at 21:37