MacKentoch/react-native-beacons-manager

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

sfreeman28 opened this issue · 3 comments

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!

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

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.

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