IOS Core Bluetooth : Writing NSData for Characteristic

后端 未结 5 965
花落未央
花落未央 2021-02-11 01:48

I am using the following code to write the 0xDE value for a Bluetooth Caracteristic (Reset Device) using the IOS Core Bluetooth :

...
NSData *bytes = [@\"0xDE\"          


        
5条回答
  •  暖寄归人
    2021-02-11 02:02

    What you are, in fact, doing here is writing the string "0xDE" to the characteristic. If you want to use binary/octal notation, you need to stay away from strings.

    int integer = 0xDE;
    NSData *data = [[NSData alloc] initWithBytes:&integer length:sizeof(integer)];
    [peripheral writeValue:data
         forCharacteristic:characteristic
                      type:CBCharacteristicWriteWithResponse];
    

提交回复
热议问题