react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

IOS >16 no location events with app closed

Open LoghinAndrei opened this issue 1 year ago â€ĸ 6 comments

Your Environment

  • Plugin version: 4.17.1
  • Platform: iOS
  • OS version: 16.7.10
  • Device manufacturer / model: Iphone 8
  • React Native version (react-native -v): 0.74.1
  • Plugin config
await BackgroundGeolocation.ready({
      // Geolocation Config
      stationaryRadius: 0, // The minimum distance the device must move beyond the stationary
      // location for aggressive background-tracking to engage.
      // Note: iOS will not detect the exact moment the device moves out of the stationary-radius. In normal conditions, it will typically
      //take ~200 meters of movement before the plugin begins tracking.
      stopOnStationary: false, // Automatically BackgroundGeolocation.stop when the stopTimeout elapses.
      enableHeadless: true, // This is required to allow us to do some logging when location events occurs
      // When set to false the location is still sent to the backend but the
      // js callbacks are not executed.
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      stopTimeout: 10, // The number of minutes to wait before turning off location-services (activity Recognition)
      // Application config
      debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
      logLevel: BackgroundGeolocation.LOG_LEVEL_INFO,
      //preventSuspend: true, //TODO
      // Android & iOS location-services will never turn off
      disableStopDetection: true,
      pausesLocationUpdatesAutomatically: false, // Need for iOS to set location-services will never turn off along with disableStopDetection
      stopOnTerminate: false,   // <-- Allow the background-service to continue tracking when user closes the app.
      startOnBoot: true,        // <-- Auto start tracking when device is powered-up.
      isMoving: true, // Consider the initial state as moving
      url: ${baseUrl}gamification/scenario/set-location-and-activity,
      batchSync: false,       // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
      autoSync: true,         // <-- [Default: true] Set true to sync each location to server as it arrives.
      headers: {              // <-- Optional HTTP headers
        "Content-Type": "application/json",
        "X-Morfin-Custom-Routing": DEV_ROUTES,
        "Authorization": ${globalUser.identity.token_type} ${globalUser.identity.access_token},
        "X-Morfin-Client": getHeaderVersion()
      },
      disableLocationAuthorizationAlert: false,
      locationAuthorizationRequest: "Any", // Alow our code to handle the authorization request
      backgroundPermissionRationale: {
        message: I18n.t("request_permissions_bk_location"),
        negativeAction: I18n.t("no_label"),
        positiveAction: I18n.t("yes_label")
      },
      locationTemplate: '{"latitude":<%= latitude %>,"longitude":<%= longitude %>, "activity": "<%= activity.type %>", "timestamp": "<%= timestamp %>", "speed": <%= speed %>, "speed_accuracy": <%= speed_accuracy %>, "heading": <%= heading %>, "accuracy": <%= accuracy %>, "altitude": <%= altitude %>, "altitude_accuracy": <%= altitude_accuracy %>, "uuid": "<%= uuid %>", "event": "<%= event %>", "odometer": <%= odometer %>, "activity_confidence": <%= activity.confidence %>, "battery_level": <%= battery.level %>, "battery_is_charging": <%= battery.is_charging %>, "mock": <%= mock %>, "is_moving": <%= is_moving %>}',
      httpRootProperty: ".",
      notification: {
        smallIcon: "mipmap/ic_notification",
        color: "#02d1bb",
        channelId: TRACKING_CHANNEL_ID,
        channelName: I18n.t('mining_title')
      }
    });

Expected Behavior

Receive background location events after the app is closed.

Actual Behavior

When the app is closed, the location icon disappears almost instantly and no other locations are sent until the application is reopened.

Steps to Reproduce

  1. Start the background location service
  2. Close app normally
  3. Start moving

Context

We have noticed that ever since IOS 16 the number of locations we receive reduced drastically. We have tried different configurations to make it more aggressive and still cannot figure out a solution.

Debug logs

Logs
2024-09-18 13:44:09.994 đŸ”ĩ-[TSLocationManager ready] 

2024-09-18 13:44:10.015 â„šī¸-[TSLocationManager doStart:] trackingMode: 1

2024-09-18 13:44:10.016 🎾-[TSGeofenceManager start] 

2024-09-18 13:44:10.017 🎾-[SOMotionDetector startDetection] 

2024-09-18 13:44:10.018 đŸ”ĩ-[TSLocationManager setPace:] 1

2024-09-18 13:44:10.021 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON

2024-09-18 13:44:10.036 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:44:10.038 🎾-[TSLocationManager startMonitoringBackgroundFetch] BackgroundFetch: ON

2024-09-18 13:44:10.046 â„šī¸-[TSLocationManager locationManager:didUpdateLocations:] Received stale motionchange location.  Retrying...

2024-09-18 13:44:10.055 â„šī¸-[TSLocationManager locationManager:didUpdateLocations:] Received stale motionchange location.  Retrying...

2024-09-18 13:44:10.103 ✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+45.67359217,+25.62389736> +/- 11.70m (speed -1.00 mps / course -1.00) @ 18.09.2024, 13:44:10 Eastern European Summer Time

2024-09-18 13:44:10.104 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON

2024-09-18 13:44:10.105 đŸ”ĩ-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 11.7

2024-09-18 13:44:10.106 🎾-[TSLocationManager startMonitoringSignificantLocationChanges] 

2024-09-18 13:44:10.110 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:44:10.113 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 0C63BBEC-69C1-48A0-B2BB-BFA3FA7A4B5B

2024-09-18 13:44:10.173 ✅-[BackgroundTaskManager createBackgroundTask] 28

2024-09-18 13:44:10.175 ✅-[TSHttpService schedulePost] LOCKED: 0C63BBEC-69C1-48A0-B2BB-BFA3FA7A4B5B

2024-09-18 13:44:10.326 đŸ”ĩ-[HttpResponse handleResponse] Response: 200

2024-09-18 13:44:10.329 ✅-[TSHttpService post:]_block_invoke DESTROY: 0C63BBEC-69C1-48A0-B2BB-BFA3FA7A4B5B

2024-09-18 13:44:10.330 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 28 OF (
    28
)

2024-09-18 13:44:11.584 ✅-[SOMotionDetector startDetection]_block_invoke Enabled M7 MotionActivity updates

2024-09-18 13:44:12.113 đŸ”ĩ-[TSLocationManager getCurrentPosition:] 

2024-09-18 13:44:12.113 🎾-[LocationManager startUpdatingLocation] ON

2024-09-18 13:44:12.117 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:44:12.117 🔴-[LocationManager stopUpdatingLocation] OFF

2024-09-18 13:44:12.118 đŸ”ĩ-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 11.7

2024-09-18 13:44:12.125 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 557AA1F2-BC16-4D93-9231-AA08B85A4D74

2024-09-18 13:44:12.128 ✅-[BackgroundTaskManager createBackgroundTask] 35

2024-09-18 13:44:12.129 ✅-[TSHttpService schedulePost] LOCKED: 557AA1F2-BC16-4D93-9231-AA08B85A4D74

2024-09-18 13:44:12.263 đŸ”ĩ-[HttpResponse handleResponse] Response: 200

2024-09-18 13:44:12.269 ✅-[TSHttpService post:]_block_invoke DESTROY: 557AA1F2-BC16-4D93-9231-AA08B85A4D74

2024-09-18 13:44:12.269 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 35 OF (
    35
)

2024-09-18 13:44:17.129 đŸ”ĩ-[TSLocationManager getCurrentPosition:] 

2024-09-18 13:44:17.129 🎾-[LocationManager startUpdatingLocation] ON

2024-09-18 13:44:17.136 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:44:17.136 🔴-[LocationManager stopUpdatingLocation] OFF

2024-09-18 13:44:17.136 đŸ”ĩ-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 11.7

2024-09-18 13:44:17.145 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 84BA7B57-E4B4-442B-A0DE-6B12B2432D52

2024-09-18 13:44:17.147 ✅-[BackgroundTaskManager createBackgroundTask] 42

2024-09-18 13:44:17.150 ✅-[TSHttpService schedulePost] LOCKED: 84BA7B57-E4B4-442B-A0DE-6B12B2432D52

2024-09-18 13:44:17.292 đŸ”ĩ-[HttpResponse handleResponse] Response: 200

2024-09-18 13:44:17.299 ✅-[TSHttpService post:]_block_invoke DESTROY: 84BA7B57-E4B4-442B-A0DE-6B12B2432D52

2024-09-18 13:44:17.300 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 42 OF (
    42
)

2024-09-18 13:44:21.688 đŸ”ĩ-[TSLocationManager getCurrentPosition:] 

2024-09-18 13:44:21.688 🎾-[LocationManager startUpdatingLocation] ON

2024-09-18 13:44:21.692 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:44:21.692 🔴-[LocationManager stopUpdatingLocation] OFF

2024-09-18 13:44:21.696 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: D45AB550-7E03-4E39-B78A-C2F2C4CE515D

2024-09-18 13:44:21.699 ✅-[BackgroundTaskManager createBackgroundTask] 55

2024-09-18 13:44:21.702 ✅-[TSHttpService schedulePost] LOCKED: D45AB550-7E03-4E39-B78A-C2F2C4CE515D

2024-09-18 13:44:21.844 đŸ”ĩ-[HttpResponse handleResponse] Response: 200

2024-09-18 13:44:21.847 ✅-[TSHttpService post:]_block_invoke DESTROY: D45AB550-7E03-4E39-B78A-C2F2C4CE515D

2024-09-18 13:44:21.847 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 55 OF (
    55
)

2024-09-18 13:44:28.852 đŸ”ĩ-[TSLocationManager onSuspend:] enabled? 1)

2024-09-18 13:45:40.278 đŸ”ĩ-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 3

2024-09-18 13:45:40.283 đŸ”ĩ-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-09-18 13:45:40.283 đŸ”ĩ-[PolygonGeofencingService locationManager:didChangeAuthorizationStatus:] 3

2024-09-18 13:45:40.283 đŸ”ĩ-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-09-18 13:45:40.283 đŸ”ĩ-[BackgroundTaskManager locationManager:didChangeAuthorizationStatus:] 3

2024-09-18 13:45:40.283 đŸ”ĩ-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-09-18 13:45:40.295 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:45:41.932 â„šī¸-[TSLocationManager log:message:] [RNBackgroundGeolocation startObserving]

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] location

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] motionchange

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] activitychange

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] heartbeat

2024-09-18 13:45:42.223 â„šī¸-[TSGeofenceManager onGeofence:] 

2024-09-18 13:45:42.223 â„šī¸-[TSGeofenceManager onGeofencesChange:] 

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] http

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] providerchange

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] schedule

2024-09-18 13:45:42.223 â„šī¸-[TSLocationManager on:success:failure:] powersavechange

2024-09-18 13:45:42.224 â„šī¸-[TSHttpService onConnectivityChange:] 

2024-09-18 13:45:42.224 â„šī¸-[TSLocationManager on:success:failure:] enabledchange

2024-09-18 13:45:42.224 â„šī¸-[TSHttpService onAuthorization:] 

2024-09-18 13:45:42.239 đŸ”ĩ-[TSLocationManager ready] 

2024-09-18 13:45:42.241 â„šī¸-[TSLocationManager doStart:] trackingMode: 1

2024-09-18 13:45:42.241 🎾-[TSGeofenceManager start] 

2024-09-18 13:45:42.242 🎾-[SOMotionDetector startDetection] 

2024-09-18 13:45:42.242 đŸ”ĩ-[TSLocationManager setPace:] 1

2024-09-18 13:45:42.245 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON

2024-09-18 13:45:42.248 ✅-[LocationDAO unlock]_block_invoke UNLOCKED ALL RECORDS

2024-09-18 13:45:42.255 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:45:42.256 🎾-[TSLocationManager startMonitoringBackgroundFetch] BackgroundFetch: ON

2024-09-18 13:45:42.257 âš ī¸-[TSLocationManager start] Already started (ignored)

2024-09-18 13:45:42.270 ✅-[SOMotionDetector startDetection]_block_invoke Enabled M7 MotionActivity updates

2024-09-18 13:45:42.273 â„šī¸-[TSLocationManager locationManager:didUpdateLocations:] Received stale motionchange location.  Retrying...

2024-09-18 13:45:42.274 ✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+45.67359217,+25.62389736> +/- 11.70m (speed -1.00 mps / course -1.00) @ 18.09.2024, 13:45:42 Eastern European Summer Time

2024-09-18 13:45:42.274 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON

2024-09-18 13:45:42.274 đŸ”ĩ-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 11.7

2024-09-18 13:45:42.275 🎾-[TSLocationManager startMonitoringSignificantLocationChanges] 

2024-09-18 13:45:42.277 â„šī¸+[LocationAuthorization run:onCancel:] status: 3

2024-09-18 13:45:42.279 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 6FBA5D79-2D45-4346-971A-7200DE2F5771

2024-09-18 13:45:42.282 ✅-[BackgroundTaskManager createBackgroundTask] 7

2024-09-18 13:45:42.285 ✅-[TSHttpService schedulePost] LOCKED: 6FBA5D79-2D45-4346-971A-7200DE2F5771

2024-09-18 13:45:42.479 đŸ”ĩ-[HttpResponse handleResponse] Response: 200

2024-09-18 13:45:42.486 ✅-[TSHttpService post:]_block_invoke DESTROY: 6FBA5D79-2D45-4346-971A-7200DE2F5771

2024-09-18 13:45:42.486 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 7 OF (
    7
)

LoghinAndrei avatar Sep 18 '24 12:09 LoghinAndrei