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進制的須要進行轉換在展現