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蓝牙搜索成功
网友评论