IOS藍牙裝置資料回調的坑

來源:互聯網
上載者:User

標籤:

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藍牙裝置資料回調的坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.