Disclaimer:
Question:
I am reading some NSData from a BLE characteristic which corresponds to a string , however I have no idea what encoding format it uses.
This is the view from the debugger on Xcode:
How can I convert it to a string? I'd like to extract this value: "<951c7c1d e0fbdcc3 7b8b0b97 5c522036>"
I tried the following with with no meanigful conversion. However XCode seems to do the job. Why?
NSData * valueAsData = characteristic.value.mutableCopy;
NSString* newStr = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
NSString* newStr2 = [[NSString alloc] initWithData:characteristic.value encoding:NSASCIIStringEncoding];
Get the descriptors associated with the characteristic. One of them should be CBUUIDCharacteristicFormatString
. This will indicate the presentation format , which will indicate the data type of the characteristic value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.