1. A callback method is sent to the Bluetooth device when it sends write data
callback after data is written
-(void) Peripheral: (cbperipheral *) Peripheral
Didwritevalueforcharacteristic: (cbcharacteristic *)
Characteristic error: (nullable nserror *) error
Because the device on our side is a blood pressure meter, it is sent to the peripheral to start the measurement, and then the measured data back, so go into the method above.
2. After the data is returned, it will enter the following method
gets the value of the charateristic
-(void) Peripheral: (cbperipheral *) Peripheral didupdatevalueforcharacteristic: ( Cbcharacteristic *) characteristic error: (nserror *) error{
Self. Uuid2data = [nsdata data];
self. Uuid2data = characteristic. Value;
nsstring *datastring = [self -convertdatatohexstr: Self. Uuid2data];
NSLog(@ "datastring =%@", datastring);
nsstring *str = @ "550f03";
if ([datastring containsstring: str]) {
nsstring *uuid2str = [datastring substringwithrange:nsmakerange(6, 16 )];
self. UUID2TF. Text = uuid2str;
}
Because the front three bits of our packet are fixed and useless, so we have to intercept it so that the useful data comes out and you need to mention characteristic. value is 16 binary needs to be converted in the show
iOS bluetooth device data callback Pit