蓝牙制造商告诉我,我需要将以下内容发送到外围设备:'P'(0x50)
如何使用Objective-C执行此操作以及如何获得响应?
代码样本将是更可取的。
这几乎回答了我的问题,但没有提供任何代码示例:peripheral writeValue: forCharacteristic: type: return null error and value
以下是一些示例代码:https://code.tutsplus.com/tutorials/ios-7-sdk-core-bluetooth-practical-lesson--mobile-20741
要来回发送数据,这是一个多步骤的过程
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse]
对于数据,您可以使用十六进制字符串创建NSData方法(https://opensource.apple.com/source/Security/Security-55471.14.18/libsecurity_transform/NSData+HexString.m)。- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
一旦你得到回调你可以用[_peripheral readValueForCharacteristic:characteristic]
读取外围设备- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
,你可以看看characteristic.value来看看价值。