Reputation: 31
It's my first question here, don't charge me too hard for it. I would like to get some advise how to sent few bytes from one iOS device to another with CBCharacteristicWriteWithoutResponse.
I did try to sent data with writeValue:forCharacteristic:type: from one iOS device (Central role) and receive it with peripheralManager:didReceiveWriteRequests: on another iOS device (Peripheral role).
I have no problem with type:CBCharacteristicWriteWitResponse, but if I replaced it with type:CBCharacteristicWriteWithoutResponse peripheral stop receive it. Whats wrong? Do I missing something or WriteWithoutResponse do not supported by CBCentralManagerDelegate?
Here some code:
@interface BleCentralDemo : NSObject <CBCentralManagerDelegate> {}
@end
@implementation BleCentralDemo
-(void) writeValue:(int)sUUID characteristicUUID:(int)cUUID p:(CBPeripheral *)p data:(NSData *)data {
[p writeValue:data forCharacteristic:cUUID type:CBCharacteristicWriteWithResponse]; // sent, received
[p writeValue:data forCharacteristic:cUUID type:CBCharacteristicWriteWithOutResponse]; // sent, not received
}
@end
@interface BlePeripheralDemo : NSObject <CBPeripheralManagerDelegate> {}
@end
@implementation BlePeripheralDemo
-(void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests {
for (CBATTRequest *request in requests){
NSLog(@"request.value:%@", request.value);
[peripheral respondToRequest:request withResult:CBATTErrorSuccess];
}
}
@end
Upvotes: 2
Views: 1063
Reputation: 240
i met the same problem today.
you should set your characteristic with CBCharacteristicPropertyWriteWithoutResponse properties.(cUUID in your code)
my characteristic is from peripheral device. created like that
[[CBMutableCharacteristic alloc] initWithType:writeableCharacteristicUUID properties:CBCharacteristicPropertyWrite | CBCharacteristicPropertyNotify | CBCharacteristicPropertyWriteWithoutResponse value :nil permissions:CBAttributePermissionsWriteable];
hope it helps
Upvotes: 2