react-native-background-geolocation: [IOS]: The plugin doesn't start to record a location when the device is moving and the app is terminated

  • Plugin version: 4.4.4
  • Platform: iOS
  • OS version: 15.1.1
  • Device manufacturer / model: iPhone 12
  • React Native version (react-native -v): 0.66.1
  • Plugin config
    const config = {
      locationAuthorizationRequest: 'Always',
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      stopTimeout: 4,
      showsBackgroundLocationIndicator: false,
      stationaryRadius: 200,
      preventSuspend: false,
      heartbeatInterval: 120,
      enableHeadless: true,
      foregroundService: true,
      stopOnTerminate: false,
      startOnBoot: true,
      debug: false,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      maxDaysToPersist: 2,
      url: `${BASE_URL}${API.ROUTE}`,
      headers: {
        Authorization: `Bearer ${accessToken}`,
      },
      autoSync: true,
    };
    
    const state = await BackgroundGeolocation.getState();

    if (!state.enabled) {
      BackgroundGeolocation.setConfig(config, (state) => {
        if (!state.enabled) {
          BackgroundGeolocation.start();
        }
      });
    } else {
      BackgroundGeolocation.ready(config, (state) => {
        if (!state.enabled) {
          BackgroundGeolocation.start();
        }
      });
    }

Expected Behavior

When the device is moving the plugin re-awake and starting record a location.

Actual Behavior

The plugin doesn’t re-awake and not starting record a location when the app is terminated and the device is moving more 200 meters and and if the app is not being used for a while (more then 1 hour about).

Steps to Reproduce

  1. Open the app
  2. Terminate the app
  3. In one hour or more start moving

Context

In the ios emulator the app works perfectly, both when it is in the foreground and in the background. On a real physical device the plugin works perfect only when the app is in the foreground or if I terminated the app and start moving at once. If preventSuspend set true the plugin works exactly in the same way as false. If the debug param is true location tracking will work correctly all the time, the plugin re-awake and starting record locations even I haven’t opened the app 2 and more days.

Debug logs

Logs ``` 2022-01-09 16:34:56.631647+0300 MyApp[20034:9826387] ℹ️-[TSDBLogger db_delete] maxAge: 259200 2022-01-09 16:34:56.632139+0300 MyApp[20034:9826395] ℹ️-[TSLocationManager init]

╔═════════════════════════════════════════════ ║ TSLocationManager (build 382) ╠══════════════════════════════════════════════

{ activityRecognitionInterval = 10000; activityType = 1; authorization = { }; autoSync = 1; autoSyncThreshold = 0; batchSync = 0; debug = 0; desiredAccuracy = “-1”; desiredOdometerAccuracy = 100; didDeviceReboot = 0; didLaunchInBackground = 0; didRequestUpgradeLocationAuthorization = 1; disableAutoSyncOnCellular = 0; disableElasticity = 0; disableLocationAuthorizationAlert = 0; disableMotionActivityUpdates = 0; disableStopDetection = 0; distanceFilter = 100; elasticityMultiplier = 1; enableTimestampMeta = 0; enabled = 1; extras = { }; geofenceInitialTriggerEntry = 1; geofenceProximityRadius = 2000; geofenceTemplate = “”; headers = { Authorization = “Bearer token”; “Content-Type” = “application/json”; }; heartbeatInterval = 800; httpRootProperty = location; httpTimeout = 60000; iOSHasWarnedLocationServicesOff = 0; isFirstBoot = 0; isMoving = 0; lastLocationAuthorizationStatus = 3; locationAuthorizationAlert = { cancelButton = Cancel; instructions = “To use background location, you must enable ‘{locationAuthorizationRequest}’ in the Location Services settings”; settingsButton = Settings; titleWhenNotEnabled = “Background location is not enabled”; titleWhenOff = “Location services are off”; }; locationAuthorizationRequest = Always; locationTemplate = “”; locationTimeout = 60; locationsOrderDirection = ASC; logLevel = 5; logMaxDays = 3; maxBatchSize = “-1”; maxDaysToPersist = 2; maxRecordsToPersist = “-1”; method = POST; minimumActivityRecognitionConfidence = 70; odometer = 0; params = { }; pausesLocationUpdatesAutomatically = 1; persistMode = 2; preventSuspend = 0; schedule = ( ); schedulerEnabled = 0; showsBackgroundLocationIndicator = 0; startOnBoot = 1; stationaryRadius = 200; stopAfterElapsedMinutes = “-1”; stopDetectionDelay = 0; stopOnStationary = 0; stopOnTerminate = 0; stopTimeout = 1; trackingMode = 1; url = “https://api/v1/track”; useSignificantChangesOnly = 0; }

2022-01-09 16:34:56.636232+0300 MyApp[20034:9826395] ℹ️-[GeofenceDAO init] CREATE TABLE IF NOT EXISTS geofences (id INTEGER PRIMARY KEY AUTOINCREMENT, identifier TEXT NOT NULL UNIQUE, latitude DOUBLE NOT NULL, sin_latitude DOUBLE NOT NULL, cos_latitude DOUBLE NOT NULL, longitude DOUBLE NOT NULL, sin_longitude DOUBLE NOT NULL, cos_longitude DOUBLE NOT NULL, radius DOUBLE NOT NULL, notifyOnEntry BOOLEAN NOT NULL DEFAULT 0, notifyOnExit BOOLEAN NOT NULL DEFAULT 0, notifyOnDwell BOOLEAN NOT NULL DEFAULT 0, loiteringDelay DOUBLE NOT NULL DEFAULT 0, extras TEXT)

2022-01-09 16:34:56.636320+0300 MyApp[20034:9826395] ℹ️-[GeofenceDAO init] CREATE index IF NOT EXISTS identifier ON geofences (identifier);CREATE index IF NOT EXISTS latitude ON geofences (latitude);CREATE index IF NOT EXISTS longitude ON geofences (longitude);CREATE index IF NOT EXISTS sin_latitude ON geofences (sin_latitude);CREATE index IF NOT EXISTS cos_latitude ON geofences (cos_latitude);CREATE index IF NOT EXISTS sin_longitude ON geofences (sin_longitude);CREATE index IF NOT EXISTS cos_longitude ON geofences (cos_longitude);

2022-01-09 16:34:57.005821+0300 MyApp[20034:9826366] 🔵-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 3

2022-01-09 16:34:57.008750+0300 MyApp[20034:9826365] 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2022-01-09 16:34:57.009944+0300 MyApp[20034:9826366] 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2022-01-09 16:34:57.010519+0300 MyApp[20034:9826378] 🔵-[BackgroundTaskManager locationManager:didChangeAuthorizationStatus:] 3

2022-01-09 16:34:57.010892+0300 MyApp[20034:9826378] 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2022-01-09 16:34:57.024790+0300 MyApp[20034:9826397] ℹ️+[LocationAuthorization run:onCancel:] status: 3

2022-01-09 16:35:03.273130+0300 MyApp[20034:9826094] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.app

2022-01-09 16:35:04.095232+0300 MyApp[20034:9826350] [TSBackgroundFetch scheduleProcessingTask] <TSBGTask identifier=com.transistorsoft.app, delay=900, periodic=1 requiresNetworkConnectivity=0 requiresExternalPower=0, enabled=1>

2022-01-09 16:35:04.115943+0300 MyApp[20034:9826094] [TSBackgroundFetch scheduleBGAppRefresh] com.transistorsoft.fetch

2022-01-09 16:35:04.143738+0300 MyApp[20034:9826391] ℹ️-[TSLocationManager log:message:] [RNBackgroundGeolocation startObserving]

2022-01-09 16:35:04.153171+0300 MyApp[20034:9826397] ℹ️-[TSLocationManager on:success:failure:] location 2022-01-09 16:35:04.153350+0300 MyApp[20034:9826378] ℹ️-[TSLocationManager on:success:failure:] motionchange 2022-01-09 16:35:04.153499+0300 MyApp[20034:9826388] ℹ️-[TSLocationManager on:success:failure:] activitychange 2022-01-09 16:35:04.153676+0300 MyApp[20034:9826350] ℹ️-[TSLocationManager on:success:failure:] heartbeat 2022-01-09 16:35:04.153902+0300 MyApp[20034:9826397] ℹ️-[TSGeofenceManager onGeofence:] 2022-01-09 16:35:04.154023+0300 MyApp[20034:9826388] ℹ️-[TSGeofenceManager onGeofencesChange:] 2022-01-09 16:35:04.154366+0300 MyApp[20034:9826350] ℹ️-[TSLocationManager on:success:failure:] http 2022-01-09 16:35:04.154446+0300 MyApp[20034:9826350] ℹ️-[TSLocationManager on:success:failure:] providerchange 2022-01-09 16:35:04.154726+0300 MyApp[20034:9826388] ℹ️-[TSLocationManager on:success:failure:] schedule 2022-01-09 16:35:04.155045+0300 MyApp[20034:9826350] ℹ️-[TSLocationManager on:success:failure:] powersavechange 2022-01-09 16:35:04.155367+0300 MyApp[20034:9826350] ℹ️-[TSHttpService onConnectivityChange:] 2022-01-09 16:35:04.155619+0300 MyApp[20034:9826388] ℹ️-[TSLocationManager on:success:failure:] enabledchange 2022-01-09 16:35:04.155682+0300 MyApp[20034:9826388] ℹ️-[TSHttpService onAuthorization:] 2022-01-09 16:35:04.156145+0300 MyApp[20034:9826350] 🔵-[TSLocationManager getCurrentPosition:] 2022-01-09 16:35:04.157032+0300 MyApp[20034:9826397] 🎾-[LocationManager startUpdatingLocation] ON 2022-01-09 16:35:04.164263+0300 MyApp[20034:9826397] 📍<+50.91216,±92.0053409> +/- 14.28m (speed -1.00 mps / course -1.00) @ 9.01.22, 16:34:51 Moscow Standard Time 2022-01-09 16:35:04.164291+0300 MyApp[20034:9826350] 🔴-[LocationManager stopUpdatingLocation] OFF 2022-01-09 16:35:04.164351+0300 MyApp[20034:9826397]

╔═══════════════════════════════════════════════════════════ ║ -[LocationManager locationManager:didUpdateLocations:] Sample 1 of 1 ╚═══════════════════════════════════════════════════════════

2022-01-09 16:35:04.164525+0300 MyApp[20034:9826395] 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 14.3 2022-01-09 16:35:04.169904+0300 MyApp[20034:9826397] ℹ️-[TSConfig persist] 2022-01-09 16:35:04.171045+0300 MyApp[20034:9826395] ℹ️-[TSConfig persist] 2022-01-09 16:35:04.171860+0300 MyApp[20034:9826350] 🔵-[TSLocationManager ready] 2022-01-09 16:35:04.172313+0300 MyApp[20034:9826395] ℹ️-[TSLocationManager doStart:] trackingMode: 1 2022-01-09 16:35:04.172872+0300 MyApp[20034:9826369] [javascript] ‘[watchPositionSuccess] -’, { coords: { altitude: 236.2, latitude: 50.9121613114, heading: -1, altitude_accuracy: 6.1, heading_accuracy: -1, accuracy: 14.3, speed_accuracy: -1, longitude: -92.0053408749141, speed: -1, floor: -1 }, timestamp: ‘2022-01-09T13:34:51.440Z’, extras: { getCurrentPosition: true }, odometer: 0, uuid: ‘2C3EC62B-41B3-42A5-81DA-EA9016F4153A’, is_moving: false, activity: { confidence: 100, type: ‘unknown’ }, battery: { is_charging: true, level: 0.6399999856948853 } } 2022-01-09 16:35:04.173851+0300 MyApp[20034:9826395] 🎾-[TSGeofenceManager start] 2022-01-09 16:35:04.173875+0300 MyApp[20034:9826378] 🎾-[SOMotionDetector startDetection] 2022-01-09 16:35:04.173998+0300 MyApp[20034:9826395] 🔵-[TSLocationManager setPace:] 0 2022-01-09 16:35:04.178507+0300 MyApp[20034:9826350] ✅-[SOMotionDetector startDetection]_block_invoke Enabled M7 MotionActivity updates 2022-01-09 16:35:04.226165+0300 MyApp[20034:9826494] 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON 2022-01-09 16:35:04.229125+0300 MyApp[20034:9826494] ℹ️+[LocationAuthorization run:onCancel:] status: 3 2022-01-09 16:35:04.234625+0300 MyApp[20034:9826397]

╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService flush:] ╚═══════════════════════════════════════════════════════════

2022-01-09 16:35:04.234833+0300 MyApp[20034:9826378] ✅-[LocationDAO unlock]_block_invoke UNLOCKED ALL RECORDS 2022-01-09 16:35:04.235042+0300 MyApp[20034:9826494] ╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService finish:error:] Success: 1 ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:04.235586+0300 MyApp[20034:9826494] ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:04.236992+0300 MyApp[20034:9826494] ℹ️+[LocationAuthorization run:onCancel:] status: 3 2022-01-09 16:35:04.237212+0300 MyApp[20034:9826494] 🎾-[TSLocationManager startMonitoringBackgroundFetch] BackgroundFetch: ON 2022-01-09 16:35:04.238183+0300 MyApp[20034:9826494] 📍<+50.91216,±92.0053409> +/- 14.28m (speed -1.00 mps / course -1.00) @ 9.01.22, 16:35:04 Moscow Standard Time 2022-01-09 16:35:04.238267+0300 MyApp[20034:9826378] ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 0.1s ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:04.238298+0300 MyApp[20034:9826494] ✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+50.91216,±92.0053409> +/- 14.28m (speed -1.00 mps / course -1.00) @ 9.01.22, 16:35:04 Moscow Standard Time 2022-01-09 16:35:04.238387+0300 MyApp[20034:9826494] 🔵-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 200 2022-01-09 16:35:04.239681+0300 MyApp[20034:9826350] 🔴-[TSLocationManager stopUpdatingLocation] 2022-01-09 16:35:04.240276+0300 MyApp[20034:9826378] 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 14.3 2022-01-09 16:35:04.240689+0300 MyApp[20034:9826378] 🎾-[TSLocationManager startMonitoringSignificantLocationChanges] 2022-01-09 16:35:04.241249+0300 MyApp[20034:9826350] ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 23454342-005B-42CC-8C82-AFAB271E93A6 2022-01-09 16:35:04.241272+0300 MyApp[20034:9826388] ╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService flush:] ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:04.274579+0300 MyApp[20034:9826494] ✅-[BackgroundTaskManager createBackgroundTask] 10 2022-01-09 16:35:04.275565+0300 MyApp[20034:9826395] ✅-[TSHttpService schedulePost] LOCKED: 23454342-005B-42CC-8C82-AFAB271E93A6 2022-01-09 16:35:04.560607+0300 MyApp[20034:9826391] 🔵-[HttpResponse handleResponse] Response: 200 2022-01-09 16:35:04.561581+0300 MyApp[20034:9826395] ✅-[TSHttpService post:]_block_invoke DESTROY: 23454342-005B-42CC-8C82-AFAB271E93A6 2022-01-09 16:35:04.561748+0300 MyApp[20034:9826395] ╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService finish:error:] Success: 1 ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:04.561924+0300 MyApp[20034:9826494] ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 10 OF ( 10 ) 2022-01-09 16:35:05.300338+0300 MyApp[20034:9826388] [connection] nw_resolver_start_query_timer_block_invoke [C19] Query fired: did not receive all answers in time for graph.facebook.com:443 flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error 2022-01-09 16:35:07.209753+0300 MyApp[20034:9826507] 🎾-[LocationManager watchPosition:] START 2022-01-09 16:35:07.212754+0300 MyApp[20034:9826507] ℹ️+[LocationAuthorization run:onCancel:] status: 3 2022-01-09 16:35:07.215340+0300 MyApp[20034:9826507] ✅-[BackgroundTaskManager createBackgroundTask] 11 2022-01-09 16:35:07.215475+0300 MyApp[20034:9826494] 🎾-[LocationManager onWatchPositionTimer:] ONESHOT 2022-01-09 16:35:08.704688+0300 MyApp[20034:9826499] ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error 2022-01-09 16:35:09.231136+0300 MyApp[20034:9826499] ⚠️-[LocationManager onTimeout:] Using last-known location <+50.91216,±92.0053409> +/- 14.28m (speed -1.00 mps / course -1.00) @ 9.01.22, 16:34:51 Moscow Standard Time 2022-01-09 16:35:09.231419+0300 MyApp[20034:9826499] ✅-[LocationManager onTimeout:] Returning best available location sample 2022-01-09 16:35:09.341573+0300 MyApp[20034:9826499] ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:17.222552+0300 MyApp[20034:9826397] 📍<+50.91216,±92.0053409> +/- 14.28m (speed -1.00 mps / course -1.00) @ 9.01.22, 16:35:13 Moscow Standard Time 2022-01-09 16:35:17.224240+0300 MyApp[20034:9826367] 🔴-[LocationManager stopUpdatingLocation] OFF 2022-01-09 16:35:17.225128+0300 MyApp[20034:9826397] ╔═══════════════════════════════════════════════════════════ ║ -[LocationManager locationManager:didUpdateLocations:] Sample 1 of 1 ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:17.225281+0300 MyApp[20034:9826391] 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 14.3 2022-01-09 16:35:17.227151+0300 MyApp[20034:9826369] [javascript] ‘[watchPositionSuccess] -’, { coords: { altitude: 236.2, latitude: 50.9121613114, heading: -1, altitude_accuracy: 5.7, heading_accuracy: -1, accuracy: 14.3, speed_accuracy: -1, longitude: -92.0053408749141, speed: -1, floor: -1 }, timestamp: ‘2022-01-09T13:35:13.295Z’, extras: { watch: true }, odometer: 0, uuid: ‘10B7D6D5-DEFA-4F96-8F85-5EAB6B2D0BCB’, is_moving: false, activity: { confidence: 100, type: ‘still’ }, battery: { is_charging: true, level: 0.6399999856948853 } } 2022-01-09 16:35:17.231445+0300 MyApp[20034:9826367] ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 10B7D6D5-DEFA-4F96-8F85-5EAB6B2D0BCB 2022-01-09 16:35:17.231564+0300 MyApp[20034:9826397] ╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService flush:] ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:17.234905+0300 MyApp[20034:9826391] ✅-[BackgroundTaskManager createBackgroundTask] 12 2022-01-09 16:35:17.237271+0300 MyApp[20034:9826391] ✅-[TSHttpService schedulePost] LOCKED: 10B7D6D5-DEFA-4F96-8F85-5EAB6B2D0BCB 2022-01-09 16:35:17.492772+0300 MyApp[20034:9826391] 🔵-[HttpResponse handleResponse] Response: 200 2022-01-09 16:35:17.499184+0300 MyApp[20034:9826570] ✅-[TSHttpService post:]_block_invoke DESTROY: 10B7D6D5-DEFA-4F96-8F85-5EAB6B2D0BCB 2022-01-09 16:35:17.499343+0300 MyApp[20034:9826570] ╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService finish:error:] Success: 1 ╚═══════════════════════════════════════════════════════════ 2022-01-09 16:35:17.499434+0300 MyApp[20034:9826570] ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 12 OF ( 11, 12 ) flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error 2022-01-09 16:35:19.537521+0300 MyApp[20034:9826367] ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error 2022-01-09 16:35:27.504030+0300 MyApp[20034:9826350] ╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error 2022-01-09 16:35:32.478877+0300 MyApp[20034:9826697] 🔴-[LocationManager stopWatchPosition] STOP 2022-01-09 16:35:32.480247+0300 MyApp[20034:9826698] ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 11 OF ( 11 ) 2022-01-09 16:35:33.379163+0300 MyApp[20034:9826567] 🔵-[TSLocationManager onSuspend:] enabled? 1) 2022-01-09 16:35:33.388324+0300 MyApp[20034:9826567] ℹ️-[TSDBLogger db_save] Log committed flipper: Desktop failed to provide certificates. Error from flipper desktop: rsocket::StreamInterruptedException: connection error Message from debugger: Terminated due to signal 9

</details>

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Maybe it because push notifications re-awake the app

They are not “push” notifications, they are “local” notifications. These debug notifications are emitted only when the app is already alive.

I suggest you install the SampleApp and try it. The Advanced App has a settings screen where you can turn off Debug mode with a switch.