我正在这样向BLE外围设备编写命令。
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
if(error) {
// [self cleanup];
NSLog(@"%@", [error localizedDescription]);
return;
}
unsigned char bytes[] = {0xA0,0x05,0xF1,0xF2,0xCC,0xFE};
NSData *data = [NSData dataWithData:self.mutableData];
data = [NSData dataWithBytes:bytes length:sizeof(bytes)];
if([service.UUID isEqual:[CBUUID UUIDWithString:kServiceUUID]]) {
for(CBCharacteristic *characteristic in service.characteristics) {
if([characteristic.UUID isEqual:[CBUUID UUIDWithString:kWriteCharactersticUUID]]) {
self.discoveredCharacteristic = characteristic;
[self.discoveredPeripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
} else if([characteristic.UUID isEqual:[CBUUID UUIDWithString:kNotifyCharactersticUUID]]) {
self.notifyCharacteristic = characteristic;
}
}
}
}
但是,如果我这样编写,则其他委托方法无法调试。而且如果我使用CBCharacteristicWriteWithResponse
,我会收到这样的错误
错误域= CBATTErrorDomain代码= 3“不允许写。 UserInfo = {NSLocalizedDescription =不允许写。}
我用LightBlue应用程序测试了BLE设备,它显示为,该属性用于Write Without Response。
您能请谁帮助我吗?