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

Background mode - iOS #37

Open
kmigntw opened this issue Jan 4, 2021 · 3 comments
Open

Background mode - iOS #37

kmigntw opened this issue Jan 4, 2021 · 3 comments

Comments

@kmigntw
Copy link

kmigntw commented Jan 4, 2021

Hi, when the app is in the background the library scans the beacons for about 15 seconds and then it stops. If I resume the app and put it in the background immediatly the library starts scanning for 15 seconds again and stops. How to increate the scanning to at least few minutes?
Here is the code I use to listen for new scanned beacons.

final StreamController<String> _beaconEventsController =
     StreamController<String>.broadcast();

   try {
     BeaconsPlugin.listenToBeacons(_beaconEventsController);

     await BeaconsPlugin.addRegion("Center", BEACON_UUID);

     _beaconEventsController.stream.listen(
         (data) async {
           await checkAllRequirements();
           if (data.isNotEmpty) {
             print('SCANNING');
             BeaconPayload beaconPayload = BeaconPayload.fromJson(data);
           }
         },
         onDone: () {},
         onError: (error) {
           print("Error: $error");
         });

     await BeaconsPlugin.runInBackground(true);

     await startMonitoring();
   } on PlatformException catch (e) {
     print(e.toString());
   }
@kmigntw
Copy link
Author

kmigntw commented Jan 15, 2021

Any advice or answer?

@PetrosPoll
Copy link

Hello! For me isn't working. I got the example that has this package on pub.dev.
Your code working ? Can you send me fll of code to try it if working for me correctly ?

Thank you!

@cloudbreakstudios
Copy link

Your issue maybe related to this (i believe this package uses this beacon library!).

https://altbeacon.github.io/android-beacon-library/battery_manager.html

Android 8.0+ Scan Limitations
Android versions 8+ restrict background processes to run for at most 15 minutes after an app was last in the foreground. Beyond this, the JobScheduler must be used to execute periodic tasks like beacon scanning, which are limited to running once every 15 minutes. This means that any betweenScanPeriod configured for < 15 minutes will be extended on Android 8 devices to only happen once every 15 minutes. Further, because Android may stagger these jobs, the actual time between scans may be 10-25 minutes on Android 8.

This does not mean that detections will take that long, as low-power scans as described in the fast detections section described above will still be active.

If you use case needs frequent scanning in the background, you can configure the library to use a Foreground Service.

I have also noticed that this package has hardcoded two properties in BeaconHelper.kt which would be good if they were configurable.

beaconManager?.backgroundBetweenScanPeriod = 0 beaconManager?.backgroundScanPeriod = 1100

For my use case I need to be able to monitor for beacons (a quick scan every 30 seconds) for nearby iBeacons. The beacons transmit for 1 minute. I need to do this whilst the app is both in the background and foreground. The foreground part works fine, but like above i think the background implementation may not be 100% Has anyone achieve similar with this package?

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

No branches or pull requests

3 participants