IOS蓝牙设备数据回调的坑

1.手机端向蓝牙设备发送写入数据后会有一个回调方法spa

//写入数据后的回调ip

- (void)peripheral:(CBPeripheral *)peripheralstring

didWriteValueForCharacteristic:(CBCharacteristic *)it

characteristic error:(nullable NSError *)errorast

由于咱们这边的设备是血压仪,是向外设发送开始测量以后,而后把测量的数据返回来,因此要进到上面的方法里。class

2.数据返回后会进入下面的方法date

//获取的charateristic的值方法

-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{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;

    }

由于咱们的数据包前面三位是固定的并且没什么用,因此要截取掉,这样有用的数据就出来了,还须要提一下characteristic.value是16进制的须要进行转换在展现

相关文章
相关标签/搜索