I think that you mean didUpdateValueForCharacteristic
instead of didWriteValueForCharacteristic
. Otherwise, the question doesn't seem correct as didWriteValueForCharacteristic
can not be used to read data from the remote device (except if you are using error codes for communication - which you shouldn't ;) ).
There are two methods to push data from the peripheral to the central: indications and notifications.
- Notifications may be discarded if sent too fast or for whatever reasons.
- Indications can only be sent one at a time (you'll have to wait until the central replies with a confirmation that the indication has been processed, before sending another one!).
I see multiple ways how your current implementation may be incorrect:
- You are not waiting for the Handle Value Confirmation packet and send the next indication too early.
- You are sending indications / notifications before the Client Characteristic Configuration has been written by the central.
- Your peripheral has flagged the characteristic to support both notifications and indications. In this case, Core Bluetooth only supports notifications and doesn't enable indications, in which case you are back at unreliable notifications ([CBPeripheral setNotifyValue:forCharacteristic:])
If the specified characteristic is configured to allow both notifications and indications, calling this method enables notifications only.