react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Fetching of location is not working properly in iOS.
Your Environment
- Plugin version: 4.8.0
- Platform: iOS
- OS version: 15.5
- Device manufacturer / model: Apple/iPhone 11
- React Native version (
react-native -v): 0.66.3 - Plugin config
BackgroundGeolocation.ready({
disableLocationAuthorizationAlert: true,
reset: true,
debug: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false,
heartbeatInterval: 60,
enableHeadless: true,
startOnBoot: true,
url: TRACKER_HOST,
autoSync: true,
params: {
device: {
uuid: await Device.getUniqueId(),
model: await Device.getModel(),
platform: await Device.getSystemName(),
manufacturer: await Device.getManufacturer(),
version: await Device.getSystemVersion(),
framework: 'IPAD',
},
},
notificationPriority: BackgroundGeolocation.NOTIFICATION_PRIORITY_MIN, // Controls the priority of the foregroundService notification and notification-bar icon.
notificationText: 'Sending locations to server', // When running the service with foregroundService: true, Android requires a persistent notification in the Notification Bar.
notificationSmallIcon: 'mipmap/status_bar_icon',
desiredAccuracy: 0,
disableElasticity: false,
activityRecognitionInterval: 10000,
allowIdenticalLocations: false,
stopDetectionDelay: 5,
stationaryRadius: 25,
preventSuspend: true,
locationTemplate:
'{ "latitude":<%= latitude %>,"longitude":<%= longitude %>,"is_moving":<%= is_moving %>,"speed":<%= speed %>,"heading":<%= heading %>,"accuracy":<%= accuracy %>, "altitude":<%= altitude %>,"altitude_accuracy":<%= altitude_accuracy %>,"timestamp":"<%= timestamp %>","event_type":"<%= event %>","uuid":"<%= uuid %>", "activity_type":"<%= activity.type %>","activity_confidence":<%= activity.confidence %>, "battery_level":<%= battery.level %>,"battery_is_charging":<%= battery.is_charging %>,"geofence_name":"","odometer":<%= odometer %>}',
batchSync: true,
maxBatchSize: 30,
maxDaysToPersist: 30,
foregroundService: true,
// Configuration added later
distanceFilter: config.distanceFilter,
elasticityMultiplier: config.elasticityMultiplier,
stopTimeout: config.stopTimeout,
});
BackgroundFetch.configure(
{
minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
stopOnTerminate: false, // <-- Android-only,
startOnBoot: true, // <-- Android-only
enableHeadless: true,
},
async (taskId) => {
console.log('- BackgroundFetch start');
await BackgroundGeolocation.getCurrentPosition({
persist: false,
samples: 1,
extras: {
context: 'background-fetch-position',
},
});
console.log('- BackgroundFetch current position: '); // <-- don't see this
BackgroundFetch.finish(taskId);
},
);
Expected Behavior
- Usecase of my App is to fetch the realtime location of user on the route He/She travels.
- Based on the location data collected , It will be used to show the user timeline on map.
- It should fetch and update the locations independent of platform (iOS/Android).
Actual Behavior
- The plugin seems to be working fine with the Android devices.
- It is not regularly updating the locations as it should despite of the common code.
- The interval or the gap between the fetching location is seeming as large compared to iOS.
Steps to Reproduce
- Not relevant to the defined use case.
Context
- As mentioned above. Using this plugin to collect the data of the route on which user travels and showing the same on map.
Debug logs
- Not relevant to the defined use case.
See Wiki Debugging and use .emailLog(yourEmail) to retrieve the log-file from your device. Attach the received .log file here.
Hello @christocracy please find log file below received over mail, Note: we have replace our server URL string with -. background-geolocation.log
Are you aware that iOS devices need to move at least 200 meters before tracking engages?
You can find more information in the API Docs Config.stationaryRadius.
What specific timestamps (start / end) should I be looking at within your logs?
In the following screenshot (recorded by me), I was stopped at the small red circle. The large red circle represents the distance I had to travel before tracking automatically engaged.
Hello @christocracy, Answering to your queries.
- Yes, I am aware about the iOS restrictions as you stated related to
Config.stationaryRadius. - What actually I should provide from the logs. I want to know which scenario logs will be helpful to you to understand it better.
- logs post opening the app
- logs post travelling certain distance
Now, I have done few testing at my end with two different devices. Here are the screenshots of the data that has been recorded.
- Blue markers are depicting my location updates.
- Red line shows the route I travelled
- Marked start/end points
- All recording has been done in the state of app killed.
- All required permissions are granted.
- iPhone 8 (iOS 15.5)

- iPhone 11 (iOS 15.1)

As it can be seen
- iPhone 8 has recorded data but the distance after which it triggered is very high.
- No data has been recorded for iPhone 11.
One more thing,
How the API callbacks can be retrieved?
onHttp seems to be returning success response. But is there any way to retrieve the request being made from the app for location updates?
Let me know What other details I can provide to resolve this.
- iPhone 8 (iOS 15.5)
This doesn't look unusual. 200 meter triggering is only typical. It can take longer.
- iPhone 11 (iOS 15.1)
iOS 15.1 had a bug related to geofence triggering. Upgrade to latest 15.5 on that device.
Tracking not updating in iOS 16.6 in XR, if App is running in Background @christocracy can you help with this
See the first post and all the information provided. You need to provide all that information too. See wiki “Debugging” and api docs “Logger”. Learn to fetch logs with .emailLog method