Question

After connecting to a bluetooth device, I'm trying to write a value to a characteristic by calling:

[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];

The right callback is getting called (peripheral:didWriteValueForCharacteristic:error:) but when I look at the data from the characteristic, it seems that the old data is persisting in characteristic.value. However, when I disconnect and reconnect to the device, the new data shows up. This only occurs on iOS 7.

Is there something I may be missing when I send the call out to the peripheral?

Was it helpful?

Solution

The behaviour you are seeing is correct. The didWriteValueForCharacteristic method confirms that the characteristic was written, but it is the peripheral itself that is the 'keeper' of the characteristic value. Core-Bluetooth won't have a new value in the characteristic until it is retrieved from the peripheral, either in response to a read request or a notify if you have subscribed to the characteristic.

From your comment it seems that the old-behaviour was to "short-circuit" the process and expose the new value immediately - This is dangerous because the peripheral may make other updates to the characteristic, so you shouldn't rely on the data without performing a read.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top