Flutter flutter_ble_lib 蓝牙组件ios

2021-08-25  本文已影响0人  xiaovtoulu

await subscriptionBle.cancel();

_scanSubscriptionScanResult?.cancel();

_scanSubscriptionScanResult =_bleManager

    .startPeripheralScan(

scanMode: ScanMode.lowLatency, callbackType: CallbackType.allMatches, allowDuplicates:true)

.listen((ScanResult scanResult)async {。。。。。

在搜索蓝牙的时候 android 是可以搜到的,Ios搜索不到,查找原因后,得出是因为ios在搜索之前必须判断蓝牙是否打开,否则搜索无效。

///蓝牙状态监听

StreamSubscription<BluetoothState> subscriptionBle;

if (subscriptionBle !=null)subscriptionBle.cancel();

subscriptionBle =_bleManager.observeBluetoothState(emitCurrentValue:true).listen((bluetoothState)async {

Fimber.d("BLE 状态 $bluetoothState");

  if (bluetoothState == BluetoothState.POWERED_ON) {

await subscriptionBle.cancel();

    _scanSubscriptionScanResult?.cancel();

    _scanSubscriptionScanResult =_bleManager

        .startPeripheralScan(

scanMode: ScanMode.lowLatency, callbackType: CallbackType.allMatches, allowDuplicates:true)

.listen((ScanResult scanResult)async {。。。。

至此ios蓝牙搜索成功

上一篇 下一篇

猜你喜欢

热点阅读