0

I have an iOS app that generates a new UUID when it's going to talk for the first time with my OSX app, which is then stored, this way I can have different characteristics identifiers for different devices.

After calling

peripheral.discoverCharacteristics([], forService: service as CBService)

in the "didDiscoverServices" method in the OSX app, in "didDiscoverCharacteristicsForService" I do this to try to find out what the new device's UUID is, so that I check if they've talked before, if not, I will store it:

for characteristic in service.characteristics {
    println("\(characteristic.UUIDString)")
}

The problem is that it prints nil, if I use characteristic.UUID instead, it gives me "Unknown (<46c35c38 c4994106 b6d351c9 8d900368>)" which is not the format I want to deal with.

Any idea why?

Another thing I've noticed is that, after testing what I've explained repeatedly with LightBlue to see what my app is advertising, sometimes certain services/characteristics seem to get stuck and just won't go away, I've even had to restore my phone to get rid of them once. Is this normal?

Thanks a lot

Lee Andrew
  • 798
  • 7
  • 28
  • 1
    If you want to print something you should use `characteristic.UUID.UUIDString` – Paulw11 Sep 07 '14 at 09:38
  • I've already tried that, but UUIDString is not available in UUID. UUID only has description/getMirror()/map() and description gives me that same output as a plain UUID. When I do it as you said, Xcode gives me "'CFUUID!' does not have a member named 'UUIDString' – Lee Andrew Sep 07 '14 at 15:59
  • It looks like a Swift issue - A `CBUUID` definitely has a `UUIDString` method, but the `UUID` property of `CBCharacteristic` is listed as an Objective-C property in the documentation. Maybe you need to retrieve it with an explicit cast first. – Paulw11 Sep 07 '14 at 20:41
  • I used a Playground to create a CFMutableCharacteristic and I can definitely access `UUID.UUIDString` - but the documentation of `CBMutableCharacteristic` does include `UUID` for both Swift and Obj-C. I don't have code to give me a Swift `CBCharacteristic` quickly – Paulw11 Sep 07 '14 at 20:46

1 Answers1

1

It seems that the documentation for CBUUID is incorrect. Although it references the UUIDString method, as you pointed out in your comments this gives an unrecognised selector exception.

I tried both Swift and Objective C code.

The CBUUID that is returned from a CBMutableCharacteristic does respond to the UUIDString selector, but obviously you don't get CBMutableCharacteristics from the discovery process.

As a design note, your approach probably isn't the most efficient. It would probably be better to have a known characteristic that contains an identifier (such as identifierForVendor) and then you can use the contents of the characteristic itself rather than the identifier of the characteristic to determine if this is a new device or not.

This way you can send the list of desired characteristics to discoverCharacteristics and write more "defined" code, rather than having to assume that the "unknown" characteristic is the identifier.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • Thats what I did this afternoon, Im generating a new vendor UUID on the Peripheral and send to the Central, rather than letting the central rely on retrieved characteristics to identify returning peripherals later on. – Lee Andrew Sep 08 '14 at 00:37