Search code examples
ioscore-bluetoothequalitycbperipheral

How to test equality on two CBPeripherals in CoreBluetooth?


So basically I am keeping a pool of peripherals during a scan for devices. When I discover a peripheral, I want to first check whether that peripheral is already in my pool. If it is already in the pool then I just want to update the handle I already have of that peripheral. If it is not already in the pool I want to add it to the pool.

The problem is that CoreBluetooth no longer allows accessing UUID's for peripherals. Both of the methods that used to access device UUID's were deprecated in iOS 7.1.

So what is the correct way to test the equality of peripherals in CoreBluetooth?


Solution

  • Yes, it was deprecated for CBPeripheral class. But new "identifier" property was added to CBPeer superclass, from which CBCentral and CBPeripheral inherit.

    So now you should use:

    peripheral.identifier.UUIDString
    

    You can check changes in AP here: https://developer.apple.com/library/ios/releasenotes/General/iOS80APIDiffs/frameworks/CoreBluetooth.html