Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't initialize CBCentralManager until needed #599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rohansingh
Copy link

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.

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.
@CLAassistant
Copy link

CLAassistant commented Jun 3, 2020

CLA assistant check
All committers have signed the CLA.

@qimingweng
Copy link

This is really important for any production app that wants a reasonable user experience!

@papaoloba
Copy link

You saved my life!

@qimingweng
Copy link

@pauldemarco do you have any opinion on this pull request?

@rockerhieu
Copy link

rockerhieu commented Jul 5, 2020

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.

rockerhieu added a commit to rockerhieu/flutter_blue that referenced this pull request Jul 5, 2020
rockerhieu added a commit to rockerhieu/flutter_blue that referenced this pull request Jul 5, 2020
@rohansingh rohansingh changed the title Don't initiliazie CBCentralManager until needed Don't initialize CBCentralManager until needed Aug 17, 2020
dmitri222 added a commit to dmitri222/flutter_blue that referenced this pull request Mar 15, 2021
revert to official version of flutter_blue when this is merged: pauldemarco#599
long-zonar added a commit to long-zonar/flutter_blue that referenced this pull request Jun 30, 2021
pauldemarco#599 Don't initialize CBCentralManager until needed
@jasaw
Copy link

jasaw commented Oct 25, 2021

@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.

@ihorkozar
Copy link

@jasaw Did you insert the delay in FlitterBluePlugin.m? Can you share the implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants