Could you tell me how to write 2(0x02) to the Characteristic Configuration Descriptor and allow Indicate on iOS?
CBPeripheral Class
-(void)writeValue:(NSData)data forDescriptor:(CBDescriptor)descriptor;
using
You should use setNotifyValue:forCharacteristic:
An error occurred with
Also, the following code has been used for Android.
I would like to do the same with iOS.
BluetoothGattServices=
mBluetoothGatt.getService(UUID.fromString);
BluetoothGattCharacteristicCharacteristic2=
s.getCharacteristic(UUID.fromString(UUID of characteristic);
int charaProp=characteristic2.getProperties();
mBluetoothGatt.setCharacteristicNotification(characteristic2,true);
// Enable the notification feature on the Sensor
BluetoothGattDescriptor descriptor
characteristic2.getDescriptor(UUID.fromString(DESCRIPTOR_UUID));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
// Write the configured descriptor
mBluetoothGatt.writeDescriptor(descriptor);
Call setNotifyValue:forCharacteristic:
and you will be given the appropriate notification or indication based on the declaration on Characteristic.>
Technically, the main difference between Notification and Indication is whether or not to respond, so this difference is absorbed by the library, whether it is iOS or Android.In addition, Android can manually change the Descriptor, but iOS forces you to use setNotifyValue:forCharacteristic:
.
Also, Android seems to have a method that allows either Notification/Indication, setCharacteristicNotification(BluetoothGattCharacteristic, boolean)
.
See also
© 2024 OneMinuteCode. All rights reserved.