setNotifyValue method

Future<bool> setNotifyValue(
  1. bool notify, {
  2. int timeout = 15,
  3. bool forceIndications = false,
})
override

Sets notifications or indications for the characteristic.

  • If a characteristic supports both notifications and indications, we use notifications. This is a limitation of CoreBluetooth on iOS.
  • forceIndications Android Only. force indications to be used instead of notifications.

Implementation

Future<bool> setNotifyValue(
  bool notify, {
  int timeout = 15, // TODO: missing implementation
  bool forceIndications = false, // TODO: missing implementation
}) async {
  /// unSubscribeFromCharacteristic
  try {
    await WinBle.unSubscribeFromCharacteristic(
      address: _address,
      serviceId: serviceUuid.str128,
      characteristicId: characteristicUuid.str128,
    );
  } catch (e) {
    log('WinBle.unSubscribeFromCharacteristic was performed '
        'before setNotifyValue()');
  }

  /// set notify
  try {
    if (notify) {
      await WinBle.subscribeToCharacteristic(
        address: _address,
        serviceId: serviceUuid.str128,
        characteristicId: characteristicUuid.str128,
      );
    }
    FlutterBluePlusWindows._isNotifying[remoteId]?[_key] = notify;
  } catch (e) {
    log(e.toString());
  }
  return true;
}