Swift 颤振中的不稳定支撑

Swift 颤振中的不稳定支撑,swift,dart,bluetooth-lowenergy,flutter,Swift,Dart,Bluetooth Lowenergy,Flutter,是否有任何方法可以检查我的设备是否支持通过dart代码执行BLE?我在找这样的东西 switch ([_manager state]) { case CBCentralManagerStateUnsupported: state = @"This device does not support Bluetooth Low Energy."; break; case CBCentralManagerStateUnauthorized: state = @"This app

是否有任何方法可以检查我的设备是否支持通过dart代码执行BLE?我在找这样的东西

switch ([_manager state])
{
case CBCentralManagerStateUnsupported:
    state = @"This device does not support Bluetooth Low Energy.";
    break;
case CBCentralManagerStateUnauthorized:
    state = @"This app is not authorized to use Bluetooth Low Energy.";
    break;
case CBCentralManagerStatePoweredOff:
    state = @"Bluetooth on this device is currently powered off.";
    break;
case CBCentralManagerStateResetting:
    state = @"The BLE Manager is resetting; a state update is pending.";
    break;
case CBCentralManagerStatePoweredOn:
    state = @"Bluetooth LE is turned on and ready for communication.";
    break;
case CBCentralManagerStateUnknown:
    state = @"The state of the BLE Manager is unknown.";
    break;
default:
    state = @"The state of the BLE Manager is unknown.";

}

我知道这是一个旧的线程,无论如何都想更新它,因为它可能会帮助其他人

您可以尝试使用FlatterBlue bluetooth插件,这是来自Flatter的新SDK

FlatterBlue的目标是从这两个平台(iOS和Android)提供最多的服务。 蓝色应该适用于Android和IOS平台。该插件还应有助于扫描和连接附近的设备。 以下是文档中的示例: [

获取一个实例:

FlutterBlue flutterBlue = FlutterBlue.instance;
isAvailable属性检查设备是否支持蓝牙

Future<bool> get isAvailable =>
    _channel.invokeMethod('isAvailable').then<bool>((d) => d);
连接/断开与设备的连接

https://github.com/pauldemarco/flutter_blue#connect-to-a-device
// Connect to the device
await device.connect();
// Disconnect from device
device.disconnect();
Discover services:
https://github.com/pauldemarco/flutter_blue#discover-services
List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
    // do something with service
});

这在Dart中目前不直接可用。您可以使用类似的插件。如果它不公开该功能,您可以提供PR。另请参阅蓝牙支持的功能请求。
flutterBlue.startScan(timeout: Duration(seconds: 4));

// Listen to scan results
var subscription = flutterBlue.scanResults.listen((scanResult) {
    // do something with scan result
    device = scanResult.device;
    print('${device.name} found! rssi: ${scanResult.rssi}');
});

// Stop scanning
flutterBlue.stopScan();
https://github.com/pauldemarco/flutter_blue#connect-to-a-device
// Connect to the device
await device.connect();
// Disconnect from device
device.disconnect();
Discover services:
https://github.com/pauldemarco/flutter_blue#discover-services
List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
    // do something with service
});
Stream<ScanResult> scan({
 ScanMode scanMode = ScanMode.lowLatency,
 List<Guid> withServices = const [],
 List<Guid> withDevices = const [],
 Duration timeout,
}) async* {
 var settings = protos.ScanSettings.create()
   ..androidScanMode = scanMode.value
   ..serviceUuids.addAll(withServices.map((g) => g.toString()).toList());

 if (_isScanning.value == true) {
   throw Exception('Another scan is already in progress.');
 }
....
  [1]: https://github.com/pauldemarco/flutter_blue#obtain-an-instance
  [2]: https://github.com/pauldemarco/flutter_blue#scan-for-devices