美文网首页
Flutter flutter_ble_lib 蓝牙组件ios

Flutter flutter_ble_lib 蓝牙组件ios

作者: xiaovtoulu | 来源:发表于2021-08-25 13:54 被阅读0次

    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蓝牙搜索成功

    相关文章

      网友评论

          本文标题:Flutter flutter_ble_lib 蓝牙组件ios

          本文链接:https://www.haomeiwen.com/subject/mugsiltx.html