ios - CoreBluetooth discover pheriperal advertisementData format -
i'm using corebluetooth discover ble device. in
- (void)centralmanager:(cbcentralmanager *)central diddiscoverperipheral:(cbperipheral *)peripheral advertisementdata:(nsdictionary *)advertisementdata rssi:(nsnumber *)rssi
i receive advertisementdata
dictionary
{ kcbadvdataisconnectable = 1; kcbadvdatalocalname = "gate_02"; kcbadvdatamanufacturerdata = <00ff0102 0303>; }
if try read advertisementdata[@"kcbadvdatamanufacturerdata"]
class obtain _nsinlinedata
. how can convert nsstring
or nsdata
object ?
nsinlinedata
is nsdata
. more specifically, (private) subclass of nsdata
- common pattern in cocoa, called class cluster.
so can use methods of nsdata
on instance of nsinlinedata
.
i'm not sure mean "converting nsdata nsstring". value of kcbadvdatamanufacturerdata
not nsstring
(as first byte 0x00
, used terminate string).
if want convert hexadecimal data decimal, there's no need convert nsstring
first. can iterate on nsdata
byte-by-byte, this:
for(nsuinteger = 0; < data.length; ++i) { byte byte = 0; [data getbytes:&byte range:nsmakerange(i, 1)]; //do byte }
Comments
Post a Comment