Flutter flutter_ble_lib 蓝牙组件ios 搜索蓝牙不成功

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容