dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
536 stars 197 forks source link

[iOS] Connect to device doesn't seem to respect timeout #478

Closed cbreezier closed 3 years ago

cbreezier commented 4 years ago
      try {
        await device.connect(timeout: Duration(seconds: 3));
      } catch (e) {
        debugPrint('Failed to connect to device: $e');
        Util.showError(context, 'Failed to connect to device');

        return await onError.call(device, e);
      }

device is a Peripheral object. This dart code works fine on Android, where a connection attempt is cancelled after 3 seconds and an exception is thrown (and caught).

However, the same code doesn't seem to do anything on iOS. The connection attempt seems to last forever.

Is the timeout parameter supported on iOS?

mikolak commented 4 years ago

It should work the same way. https://github.com/Polidea/MultiPlatformBleAdapter/blob/master/iOS/classes/BleModule.swift#L400

dokinkon commented 4 years ago

Same issue with version 2.2.6

jaromeyer commented 4 years ago

i have the same issue

jaromeyer commented 4 years ago

@cbreezier @dokinkon As a workaround you can use Dart's timeout method: await device.connect().timeout(Duration(seconds: 3));

If you have some issues with scanning or connecting to the device once it's available/in range again, also add this hack:

try {
   await device.disconnectOrCancelConnection();
} catch (e) {}
HerrNiklasRaab commented 3 years ago

@mikolak Any upates?

mikolak commented 3 years ago

No news, sorry. I'll try to fix it this month.

mikolak commented 3 years ago

Almost a half year later, but the issue will be fixed in the nearest release, probably by the end of the week.