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

Scanning stops after app in background for 5 minutes (iOS) #189

Open
sfreeman28 opened this issue Jun 2, 2020 · 3 comments
Open

Scanning stops after app in background for 5 minutes (iOS) #189

sfreeman28 opened this issue Jun 2, 2020 · 3 comments

Comments

@sfreeman28
Copy link

Version

1.0.7

Platform

iOS

OS version

iOS 13.3

Steps to reproduce

  1. Use startRangingBeaconsInRegion()
  2. Listen for beaconsDidRange events and log nearby beacons
  3. Put app into background (or turn off screen)
  4. Witness that after ~5 minutes the beaconsDidRange events stop being dispatched
  5. Bring app to foreground and the events immediately start again

Expected behavior

Expect the events to continue while app is in background

Actual behavior

Almost exactly on 5 minutes the events stop being dispatched.
Not sure if this is related to iOS background limits or something with CLBeaconRegion.

Android working as expected in background.
Any help appreciated!

@sfreeman28
Copy link
Author

Also I have enabled background modes as described here:
https://github.com/MacKentoch/react-native-beacons-manager/blob/master/BACKGROUND_MODES.md

And requested Location Always permission.

The events do work on background for the first 5 minutes, then it suddenly stops.
Thanks

@27comar
Copy link

27comar commented Jun 5, 2020

Hi,

I also encountered this problem and was indeed able to counter it.
What I did is I used react-native-background-geolocation.
Normally this library is used to know and record the user geolocation. However, in my app it is only used to prevent the OS to kill it while in background. Indeed, no listeners are set for the library event, it is only configured to make the app continuously run in background with the preventSuspend parameter :

if (Platform.OS === 'ios') {
      Beacons.requestAlwaysAuthorization();
      Beacons.startUpdatingLocation();
      BackgroundGeolocation.ready({
        reset: true,
        preventSuspend: true // Make the app run continuously in background
      }, (state) => {
        console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
        if (!state.enabled) {
          // Start the backgroundGeolocation service
          BackgroundGeolocation.start(function () {
            console.log("- Start success");
          });
        }
      });
    }

The service is started when I start the beacons monitoring and stopped when it is ended, so the app only runs in background when it needs to. I only use it on the iOS app with the condition check.

To stop it, you do it like that :

if (Platform.OS == "ios") {
   BackgroundGeolocation.stop();
}

Since I didn't publish my app, I'm not 100% sure if Apple will allow this usage during its review process. Normally it should, because the app indeed uses locations for the beacons and it is an acceptable use case for performing background tasks.

@iSaBo96
Copy link

iSaBo96 commented Nov 26, 2022

@27comar I want the same result as you write. But when if use the background-geolocation library with this library, i get the error, descibed in this following post: #251 Do you know why and is it still going on with you?

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