iOS bluetooth device data callback Pit

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.