flutter_blue
flutter_blue copied to clipboard
Don't initialize CBCentralManager until needed
By deferring the initialization of CBCentralManager
, we are able to
defer prompting for Bluetooth permission on iOS until a flutter_blue
method is called. Otherwise, the Bluetooth permission prompt appears
right when the app starts up.
This is really important for any production app that wants a reasonable user experience!
You saved my life!
@pauldemarco do you have any opinion on this pull request?
For those who want to use this PR before it is merged:
dependencies:
flutter_blue:
# TODO: revert to official version of flutter_blue when this is merged: https://github.com/pauldemarco/flutter_blue/pull/599
git:
url: https://github.com/tidbyt/flutter_blue.git
ref: 4ed5e9980139a9521fcd4dcdd7a97084875bb7b6
And of course don't forget to subscribe to this PR.
@rohansingh This PR has the unfortunate side effect where calling isOn
always returns false if centralManager
is initialized in the same call. This is caused by race condition of reading the Bluetooth state while the Bluetooth subsystem is still initializing.
As a workaround, I just added a small delay between the centralManager
init call and the isOn
call.
@jasaw Did you insert the delay in FlitterBluePlugin.m? Can you share the implementation?