0

So here's the situation: I am able to see the services inside the peripheral, however I have not been able to decode them properly without calling discoverServices:.

The question is: how can i convert a CBUUID.data into the actual NSString that is stored?

-The Data appears as <20c0b7a0 982c11e2 9e960800 200c9a66>

-But the real value being stored is DF8EE4F1-4899-4FF6-8EE4-75890

BUT before jumping to any conclusions, I've tried every decoding method I have found including:

1.)

NSString *uuidString = [NSString stringWithUTF8String:[uuidData bytes]];

2.)

NSString *uuidString = [[NSString alloc]  initWithBytes:[uuidData bytes]
              length:[uuidData length] encoding: NSUTF8StringEncoding];
//I tried this method with every single type of encoding actually

Both of these methods above were (null);

3.)

size_t length = [uuidData length];
unsigned char aBuffer[length];
[uuidData getBytes:aBuffer length:length];
aBuffer[length - 1] = 0;
NSLog(@"uuid: %s", aBuffer);

And this method returned: ¿∑†ò,‚ûñ

If anyone can decode or encode this properly I will be eternally grateful!!!

Makleesh
  • 988
  • 10
  • 15
  • How in the world does this compile if you aren't even using the proper pointer types? – CodaFi Jun 14 '13 at 05:41
  • Can you elaborate on that? – Makleesh Jun 14 '13 at 05:45
  • NSString *UUIDString = CFUUIDCreateSring(nil, [youSomeThingWithCBUUID UUID]); ? – Larme Jun 14 '13 at 05:48
  • @CodaFi Thanks. I was trying to follow the answer here: http://stackoverflow.com/a/555106/1060861 It compiles for some reason though. And Larme, thanks man but CBUUID doesn't have a UUID property – Makleesh Jun 14 '13 at 05:54
  • @CodaFi that just turns the CBUUID (in NSData) into a String. It doesn't actually convert it and then turn into a string – Makleesh Jun 14 '13 at 06:12
  • @Makleesh - Have you actually run either of the solutions there? They do in fact produce the string representation of the CBUUID, as you would see on the device or provide to the framework. I even show the output produced by my hacked-together method. They do exactly what you want. – Brad Larson Jun 14 '13 at 13:13
  • @BradLarson I made a massive mistake and your awesome method made me realize it!! While entering services into the peripheralManager I was accidentally swapping UUID's. Thank you so much!!! – Makleesh Jun 14 '13 at 19:15
  • @Makleesh - I've done that myself, which is fun to debug. That, and the nil UUIDs you sometimes get back on certain iOS 6.x versions. iOS 7 looks to make this a little more robust. – Brad Larson Jun 14 '13 at 20:10
  • @BradLarson oh yeaaa definitelyyy. Thanks again! – Makleesh Jun 19 '13 at 02:58

0 Answers0