Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS connectToDevice() after finding device ID fails with PlatformException #845

Open
alexpriceuk opened this issue Feb 14, 2024 · 1 comment

Comments

@alexpriceuk
Copy link

alexpriceuk commented Feb 14, 2024

All permissions are enabled, I do the following as per documentation

await _flutterReactiveBle
        .scanForDevices(withServices: services)
        .timeout(Duration(seconds: scanTimeoutDurationSeconds))
        .firstWhere((device) {
      _deviceId = device.id;
      debugPrint('device discovered: $device');

      return true;
    }).onError((error, stackTrace) {
      debugPrint('error: $error');
      debugPrint('stackTrace: $stackTrace');
      _bleConnectionState.value = BleConnectionStatus.disconnected;
      throw BleBikeNotFoundException();
    });

    _connectionStateStream = _flutterReactiveBle
        .connectToDevice(
      id: _deviceId!,
    )
        .listen((update) {
      _handleConnectionStreamUpdate(update);
    },
      onError: (Object e) => {
            debugPrint('Connecting to device $_deviceId resulted in error $e'),
            dispose(),
            throw BleConnectionError(),
          });

The logs from this are as follows:

device discovered: DiscoveredDevice(id: E390E5E7-EC0B-37B9-3F26-27068C768EB7, name: imx8mmea-ucom, serviceData: {}, serviceUuids: [a25478a0-c922-11ee-9603-d3a9796f3cfa], manufacturerData: [], rssi: -56, connectable: Connectable.available)

Connecting to device E390E5E7-EC0B-37B9-3F26-27068C768EB7 resulted in error PlatformException(reactive_ble_mobile.Central.(unknown context at $105b88464).Failure:2, The operation couldn’t be completed. (reactive_ble_mobile.Central.(unknown context at $105b88464).Failure error 2.), {}, null)

I'm running on latest iOS 17.3.1 on iPhone 13 mini
I've added and enabled all permissions

Can anybody offer any advice?

@alexpriceuk
Copy link
Author

After much headache I found a similar issue where the package would throw the same error while using discoverServices() (now deprecated). #724

For some reason I have to use a delay between connecting and subscribing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant