diff --git a/ios/Classes/FlutterBluePlugin.m b/ios/Classes/FlutterBluePlugin.m index 65a73b6d..2b9de34f 100644 --- a/ios/Classes/FlutterBluePlugin.m +++ b/ios/Classes/FlutterBluePlugin.m @@ -48,7 +48,6 @@ + (void)registerWithRegistrar:(NSObject*)registrar { FlutterEventChannel* stateChannel = [FlutterEventChannel eventChannelWithName:NAMESPACE @"/state" binaryMessenger:[registrar messenger]]; FlutterBluePlugin* instance = [[FlutterBluePlugin alloc] init]; instance.channel = channel; - instance.centralManager = [[CBCentralManager alloc] initWithDelegate:instance queue:nil]; instance.scannedPeripherals = [NSMutableDictionary new]; instance.servicesThatNeedDiscovered = [NSMutableArray new]; instance.characteristicsThatNeedDiscovered = [NSMutableArray new]; @@ -67,7 +66,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { NSNumber *logLevelIndex = [call arguments]; _logLevel = (LogLevel)[logLevelIndex integerValue]; result(nil); - } else if ([@"state" isEqualToString:call.method]) { + return; + } + if (self.centralManager == nil) { + self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; + } + if ([@"state" isEqualToString:call.method]) { FlutterStandardTypedData *data = [self toFlutterData:[self toBluetoothStateProto:self->_centralManager.state]]; result(data); } else if([@"isAvailable" isEqualToString:call.method]) { diff --git a/lib/src/flutter_blue.dart b/lib/src/flutter_blue.dart index 6d2f76e9..40957fdc 100644 --- a/lib/src/flutter_blue.dart +++ b/lib/src/flutter_blue.dart @@ -74,10 +74,8 @@ class FlutterBlue { } _setLogLevelIfAvailable() async { - if (await isAvailable) { - // Send the log level to the underlying platforms. - setLogLevel(logLevel); - } + // Send the log level to the underlying platforms. + setLogLevel(logLevel); } /// Starts a scan for Bluetooth Low Energy devices and returns a stream