startAdvertising method

Future<void> startAdvertising({
  1. BluetoothAdvertisementData advertisementData = const BluetoothAdvertisementData(),
  2. BluetoothAdvertisementData? scanResponse,
  3. BluetoothAdvertisingSettings settings = const BluetoothAdvertisingSettings(),
})

开始 BLE 广播。

参数:

  • advertisementData:主广播数据,默认 const BluetoothAdvertisementData()。 跨平台推荐只放 localName 与少量 serviceUuids,避免超过传统 31 字节限制。
  • scanResponse:扫描响应数据,默认 null。Android 支持;iOS/macOS 当前忽略; Linux/Windows/Web 不支持广播。
  • settings:广播设置,默认 const BluetoothAdvertisingSettings(),即 balanced、 medium、connectable true、无超时。Android 支持这些设置;iOS/macOS 当前忽略设置; Linux/Windows/Web 不支持广播。

平台差异:Android 支持 manufacturer/service data、scan response 和功率/模式设置; iOS/macOS 当前只使用 BluetoothAdvertisementData.localNameserviceUuids; Linux/Windows/Web 不支持。

Implementation

Future<void> startAdvertising({
  BluetoothAdvertisementData advertisementData =
      const BluetoothAdvertisementData(),
  BluetoothAdvertisementData? scanResponse,
  BluetoothAdvertisingSettings settings =
      const BluetoothAdvertisingSettings(),
}) {
  throw UnimplementedError('startAdvertising() has not been implemented.');
}