flutter_blue icon indicating copy to clipboard operation
flutter_blue copied to clipboard

Enables background usage of flutter-blue

Open rmawatson opened this issue 6 years ago • 24 comments

Android: Swaps activity() calls for context() where only a context is required. The only place an activity is required is when requesting permissions. This patch will return an error when the plugin is used where permissions have not been granted, and there is no activity available to request permissions

iOS: To use bluetooth-central background role and continue to processes in the background it is required that a unique ID (CBCentralManagerOptionRestoreIdentifierKey) be set when the CBCentralManager is initialized. (https://developer.apple.com/documentation/corebluetooth/cbcentralmanageroptionrestoreidentifierkey?language=objc).

Delays instanciation of the cbcentralmanager to when it is first used, so allow setting of a unique id from dart.

When CBCentralManagerOptionRestoreIdentifierKey is set, the CBCentralManagerDelegate must implement centralManager:willRestoreState. The current implementation is empty as it appears that setting a unique ID is sufficient (and the bluetooth-central role) is sufficient to stop iOS killing the app after a few minutes once it has been backgrounded iff a there is ongoing bluetooth activity (connection is active or pending, or a scan is in progress).

This has a side effect of printing an API-MISUSE warning when CBCentralManagerOptionRestoreIdentifierKey is not used, because the method centralManager:willRestoreState is always implemented. The warning is harmless when not using CBCentralManagerOptionRestoreIdentifierKey.

Dart:

To support the setting of a unique Id, introduces setUniqueId(String). This should be called before any methods that will instanciate the native instance of the cbcentralmanager.

rmawatson avatar Feb 14 '19 12:02 rmawatson

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 14 '19 12:02 CLAassistant

Additional Notes:

iOS:

Even when a unique ID is set, the app could still theoretically be killed for other reasons by iOS (although I have not experienced this).

If the app is killed by iOS at any point and bluetooth-tasks are ongoing, iOS will restart the app and willRestoreState method will be called on the CBCentralManagerDelegate. It allows about 10 seconds to handle the event, before the app is killed again. It may be nice to allow registering a handler in flutter that can be called to handle such events. This would be iOS only.

States that can be saved and restored:

https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/central_manager_state_restoration_options?language=objc

Additionally it would be good to be able to pass through the application restart reason. Currently flutter has no way of knowing why it was started and main() will run if it was started to handle something through willRestoreState. If it was started to handle this callback, the ideal would be run this in a standalone isolate, passing the various restored states to the handler, but allow the main to exit without attempting to run any code by checking the start reason.

rmawatson avatar Feb 14 '19 13:02 rmawatson

changed PR branch and created new PR here

rmawatson avatar Mar 09 '19 15:03 rmawatson

Any update of this issue ?

fvisticot avatar Jun 20 '19 15:06 fvisticot

Any Update :) ?

AlexanderCollins avatar Aug 08 '19 23:08 AlexanderCollins

is there a timeline or even a plan to intgrate this?

bobulus77dev avatar Nov 15 '19 15:11 bobulus77dev

any update ? I've been loooking a way to use the lib in background...

freedreamer82 avatar Nov 19 '19 17:11 freedreamer82

Can we get this merged? @pauldemarco is this on the roadmap to be merged? Lots of people needing this functionality.

valtbarbos avatar Nov 21 '19 17:11 valtbarbos

Do we have any updates on this ?

Drkstr avatar Feb 04 '20 13:02 Drkstr

Hi I have no updates on this

4 Şub 2020 Sal, saat ÖS 4:49 tarihinde Rakshak Raghavan < [email protected]> şunu yazdı:

Do we have any updates on this ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pauldemarco/flutter_blue/pull/191?email_source=notifications&email_token=ABJMOY6H4E6RSWVJD27LVK3RBFW7XA5CNFSM4GXOB7O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKXV2BI#issuecomment-581917957, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJMOYYCRTWHY2RRMDM54Z3RBFW7XANCNFSM4GXOB7OQ .

icaglar avatar Feb 06 '20 07:02 icaglar

We really need this. Any ETA?

TobiasHeidingsfeld avatar Mar 09 '20 15:03 TobiasHeidingsfeld

hello, i was working in somehit to help this covid pandemic and this its feature its gonna be really helpful, do you have a time where this will be implemented? i actually try to add the code to my code but is still not working.

will really appreciate any updated. thanks!!

Arkangel12 avatar Apr 12 '20 01:04 Arkangel12

Any new on this? Need this feature really bad and would love to get feedback.

arc41t3ct avatar Jun 30 '20 11:06 arc41t3ct

any updates on this?

allanwhatsbusy avatar Aug 25 '20 00:08 allanwhatsbusy

Hi Paul, We all need this.Could you please let us know road map to merge this PR ?

vjgoutham avatar Sep 04 '20 17:09 vjgoutham

An ETA would be great also is it possible to allow for multiple unique ids?

DevNico avatar Sep 28 '20 06:09 DevNico

Looks like some merge conflicts, but definitely would be useful to have this ASAP.

mdridley avatar Nov 20 '20 06:11 mdridley

is there any update how can i scan results when app is in background

ramashish-headerlabs avatar Dec 11 '20 07:12 ramashish-headerlabs

Why is this still open as you created #210 instead?

JuniorJPDJ avatar Jan 16 '21 00:01 JuniorJPDJ

Could you have this fix in last version of plugin??

M3sca avatar Jan 27 '21 20:01 M3sca

Can this fix go to the latest version? 👍 I consider this a highly requested feature by users

dorsamet avatar Mar 09 '21 16:03 dorsamet

Any update please?

ezranbayantemur avatar Mar 23 '21 13:03 ezranbayantemur

What is the current status of flutter blue background processes?

Jeancr123 avatar Jan 06 '23 00:01 Jeancr123

What is the current status of flutter blue background processes?

I think the future is to switch to FlutterBluePlus which is a fork of this inactive repository. It's almost a drop-in replacement and it works well in background...

xbug42 avatar May 10 '23 10:05 xbug42