chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
791 stars 478 forks source link

[Feature]: Make CBCentralManagerOptionShowPowerAlertKey configurable (iOS) #822

Closed fesp closed 8 months ago

fesp commented 8 months ago

FlutterBluePlus Version

1.31.12

Flutter Version

3.19.4

What OS?

iOS

OS Version

17.3.1

Bluetooth Module

?

What is your feature request?

At the moment CBCentralManagerOptionShowPowerAlertKey is hardcoded to YES. It would be nice if the app could set this to NO. Currently my app shows a Flutter dialog if the Bluetooth adapter is turned off. But in order to detect this state I need to use FlutterBluePlus.adapterState which causes the native dialog to appear.

So at this point I have two dialogs. If then dismiss the native dialog, the Flutter dialog is still there (of course). It is not an option to remove the Flutter dialog because (as far as I know) there is no way to re-trigger the native dialog once dismissed.

Logs

-
chipweinberger commented 8 months ago

open a PR. no need to file an issue.

thanks though.

chipweinberger commented 8 months ago

maybe this

FlutterBluePlus.setOptions({bool iosShowPowerAlert}}

fesp commented 8 months ago

open a PR. no need to file an issue.

thanks though.

You are right of course. I did have a go at it (with the setOptions approach you mentioned above), but found that the very first method call is flutterHotRestart, which causes CBCentralManager to initialise. Therefore setOptions comes too late. Any thoughts on this?

chipweinberger commented 8 months ago

don't use FlutterBluePlus._invokeMethod

instead directly call _methodChannel.invokeMethod

chipweinberger commented 8 months ago

or maybe better, add an option to skip calling _initFlutterBluePlus in this function

static Future _invokeMethod(String method, [dynamic arguments])

fesp commented 8 months ago

Yes, that solved the issue. Thanks! Need to finish some work first but then I'll create the PR.