connect method

Future<void> connect(
  1. String deviceId, {
  2. bool autoConnect = false,
  3. Duration? timeout,
})

连接 BLE 设备。

参数:

  • deviceId:设备标识,无默认值。Android 使用 MAC 地址;Linux 使用 BlueZ Address 或 DBus object path;Windows 使用扫描得到的蓝牙地址或 WinRT DeviceId;iOS/macOS 使用扫描得到的 peripheral UUID;Web 使用已通过设备选择器授权的浏览器设备 ID。
  • autoConnect:是否使用 Android 自动连接语义,默认 false。iOS/macOS/Linux/Windows/Web 会忽略该参数。 前台主动连接推荐保持 false;后台等待设备回连时 Android 可设为 true
  • timeout:连接超时,默认 null 表示不由插件自动超时。前台连接推荐 Duration(seconds: 10)Duration(seconds: 15);Android autoConnect: true 语义下连接会立即返回,不建议依赖超时判断最终连接结果。Web 只能连接当前站点已授权设备。

Implementation

Future<void> connect(
  String deviceId, {
  bool autoConnect = false,
  Duration? timeout,
}) {
  throw UnimplementedError('connect() has not been implemented.');
}