1

I have a case where I actually need the raw 'bytes' data from a bluetooth characteristic converted/copied into a String. When I print the characteristic using

print("My characteristic: (String(describing: myCharacteristic))")

I get the following result

My characteristic: Optional(<CBCharacteristic: 0x28325c240, UUID = System ID, properties = 0x2, value = {length = 8, bytes = 0xfdf648dc3ae1697b}, notifying = NO>)

Specifically, I need to get 0xfdf648dc3ae1697b into a string.

I can use NSData to get the value data

let nsdataStr = NSData.init(data: (characteristic.value)!)

print("Raw: (nsdataStr)")

and I get

Raw: {length = 8, bytes = 0xfdf648dc3ae1697b}

but I am stuck when it comes to converting the whole value output into a string i.e. "{length = 8, bytes = 0xfdf648dc3ae1697b}".

0 Answers0