Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didWriteValueForCharacteristic returns a characteristic.value as null ios

I am writing data using [peripheral writeValue:startFrame forCharacteristic:cbWriteCharacteristic type:CBCharacteristicWriteWithResponse]; which calls "didWriteValueForCharacteristic as shown below"

- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{ 
    NSLog(@"characteristic.value %@",characteristic.value);
    NSLog(@"Write Data characteristic.value %@",characteristic.value);

    CBCharacteristic * cbReadCharacterstic = [self getCharacteristicWtihCBUUID:MHSW_READ_CHARACTERISTIC_ID];
    [peripheral setNotifyValue:TRUE forCharacteristic:cbReadCharacterstic];

}

When i am printing value of "characteristic.value" in did write method it returns null. Instead it should give value of data to be sent. When i am printing value of charateristics in write method:- " <CBCharacteristic: 0x166d0, UUID = D0F0-9DD7-7047, properties = 0x8, value = (null), notifying = NO>" value appears null in write method itself. Why it is coming so?

What should i do to resolve. Thanks in advance.

like image 800
Zalak Patel Avatar asked Nov 10 '14 06:11

Zalak Patel


1 Answers

A call to didWriteValueForCharacteristic informs you that a write with response has completed (i.e. the response has been received). It does not tell you anything about the value of that characteristic, so nil is the correct value.

The characteristic value could have changed between the execution of your write and the reception of the response.

If you want the current value of the characteristic then you need to issue a read request (or subscribe to value changes via notify).

like image 137
Paulw11 Avatar answered Nov 18 '22 12:11

Paulw11