scientifichackers / flutter-rx-ble

A Flutter BLE plugin, based on RxAndroidBle and RxBluetoothKit.
GNU Lesser General Public License v3.0
35 stars 18 forks source link

[iOS] return know peripherals without scanning #7

Open fvisticot opened 5 years ago

fvisticot commented 5 years ago

I would like to avoid scanning again if my device know the identifier of my BLE Objects. Apple provide this interesting method:

retrievePeripheralsWithIdentifiers : https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipheralswithidentifie?language=objc

Can you please expose this method in the API ?

devxpy commented 5 years ago

I don't think the underlying libraries, RxBluetoothKit / RxAndroidBle expose this.

You better file an issue there, since this library is fully dependent on those.

devxpy commented 5 years ago

I'm just using the connect method, with the deviceId stored in shared preferences and a timeout.

(Passing autoConnect: true does the scanning for you automatically.)

final stream = RxBle.connect(deviceId, autoConnect: true).timeout(
  Duration(seconds: 10),
  onTimeout: (sink) {
    sink.close();
    ...
  },
);

await for (state in stream) {
   ...
}
fvisticot commented 5 years ago

I have checked the doc for iOS and it seems the methods are available:

https://github.com/Polidea/RxBluetoothKit/wiki/9.-Other-functionalities#retrieving-peripherals

It would be nice if you could wrap the 2 methods:

manager.retrieveConnectedPeripherals(withServices: services) manager.retrievePeripherals(withIdentifiers: identifiers)

devxpy commented 5 years ago

Thanks for the research. How are you planning to make this feature cross-platform?

fvisticot commented 5 years ago

In addition, how can I re connect a device that i not yet "in range" ? I would like to connect without timeout to connect the device when he will be in range.