I can\'t find any official way to get a UUID string back out of a CBUUID. These UUIDs can be 2 or 16 bytes long.
The goal is to store CBUUIDs in a file somewhere as
Here is swift extension of Brad Larson's answer :
import CoreBluetooth
extension CBUUID {
func representativeString() -> String {
let data = self.data
let bytesToConvert = data.length
let uuidBytes = UnsafePointer<CUnsignedChar>(data.bytes)
var outputString = String()
for currentByteIndex in 0..<bytesToConvert {
switch currentByteIndex {
case 3,5,7,9:
outputString += String(format: "%02x-",uuidBytes[currentByteIndex])
default:
outputString += String(format: "%02x",uuidBytes[currentByteIndex])
}
}
return outputString
}
}
From iOS 7.1 UUIDString
property is there but for specific iOS7, above extension is good option.
I know it's been 7 month since it was asked and answered, but... CBUUID
is “toll-free bridged” to CFUUID
and the easiest way to convert is
//CBUUID* uuid = descr.UUID;
NSString* str = CFUUIDCreateString(nil, uuid);