標籤:
1.手機端向藍牙裝置發送寫入資料後會有一個回調方法
//寫入資料後的回調
- (void)peripheral:(CBPeripheral *)peripheral
didWriteValueForCharacteristic:(CBCharacteristic *)
characteristic error:(nullable NSError *)error
因為我們這邊的裝置是血壓儀,是向外設發送開始測量之後,然後把測量的資料返回來,所以要進到上面的方法裡。
2.資料返回後會進入下面的方法
//擷取的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;
}
因為我們的資料包前面三位是固定的而且沒什麼用,所以要截取掉,這樣有用的資料就出來了,還需要提一下characteristic.value是16進位的需要進行轉換在展示
IOS藍牙裝置資料回調的坑