question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS Simulator stop to receive location update when app is killed

See original GitHub issue

Your Environment

  • Plugin version:
  • Platform: iOS
  • OS version: 13.7
  • Device manufacturer and model:
  • Running in Simulator: iPhone 11
  • React Native version: 4.13.0
  • Plugin configuration options:
  • Link to your project:

Context

Expected Behavior

Actual Behavior

Possible Fix

Steps to Reproduce

Context

Debug logs

I try to receive location updates with this resource. It work very well when the app is foreground but when i kill app from simulator it stop to receive update. The permission is always and debug location is freeway!

This is my code:

const App: () => React$Node = () => {

React.useEffect(()=>{ BackgroundGeolocation.configure({ desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY, stationaryRadius: 5, distanceFilter: 50, notificationTitle: ‘Background tracking’, notificationText: ‘enabled’, debug: false, startOnBoot: true, stopOnTerminate: false, locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER, interval: 10000, fastestInterval: 5000, activitiesInterval: 10000, stopOnStillActivity: false, });

BackgroundGeolocation.on('location', (location) => {
  // handle your locations here
  // to perform long running operation on iOS
  // you need to creatße background task
  BackgroundGeolocation.startTask(taskKey => {
    // execute long running task
    // eg. ajax post location
    // IMPORTANT: task has to be ended by endTask
    console.log("NEW LOCATION",location);
    BackgroundGeolocation.endTask(taskKey);
  });
});



BackgroundGeolocation.on('error', (error) => {
  console.log('[ERROR] BackgroundGeolocation error:', error);
});

BackgroundGeolocation.on('start', () => {
  console.log('[INFO] BackgroundGeolocation service has been started');
});

BackgroundGeolocation.on('stop', () => {
  console.log('[INFO] BackgroundGeolocation service has been stopped');
});

BackgroundGeolocation.on('authorization', (status) => {
  console.log('[INFO] BackgroundGeolocation authorization status: ' + status);
  if (status !== BackgroundGeolocation.AUTHORIZED) {
    // we need to set delay or otherwise alert may not be shown
    setTimeout(() =>
      Alert.alert('App requires location tracking permission', 'Would you like to open app settings?', [
        { text: 'Yes', onPress: () => BackgroundGeolocation.showAppSettings() },
        { text: 'No', onPress: () => console.log('No Pressed'), style: 'cancel' }
      ]), 1000);
  }
});

BackgroundGeolocation.on('background', () => {
  console.log('[INFO] App is in background');
});

BackgroundGeolocation.on('foreground', () => {
  console.log('[INFO] App is in foreground');
});

BackgroundGeolocation.on('abort_requested', () => {
  console.log('[INFO] Server responded with 285 Updates Not Required');

  // Here we can decide whether we want stop the updates or not.
  // If you've configured the server to return 285, then it means the server does not require further update.
  // So the normal thing to do here would be to `BackgroundGeolocation.stop()`.
  // But you might be counting on it to receive location updates in the UI, so you could just reconfigure and set `url` to null.
});

BackgroundGeolocation.on('http_authorization', () => {
  console.log('[INFO] App needs to authorize the http requests');
});

BackgroundGeolocation.checkStatus(status => {
  console.log('[INFO] BackgroundGeolocation service is running', status.isRunning);
  console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
  console.log('[INFO] BackgroundGeolocation auth status: ' + status.authorization);

  // you don't need to check status before start (this is just the example)
  if (!status.isRunning) {
    BackgroundGeolocation.start(); //triggers start on start event
  }
});

// you can also just start without checking for status
// BackgroundGeolocation.start();

},[])

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:10

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Location not updated when user killed the application
Whenever user killed the app, the location update get stop in actual device. Is there any way to resume the app for location...
Read more >
Continuous location in background … | Apple Developer Forums
I am writing an iOS app that requires continuous location updates while being in the background. I am using CLLocationManager and here is...
Read more >
Getting Location Updates for iOS 7 and 8 when the App is Killed
In iOS 7.0, Apple prevents the location update when the app is killed/terminated/suspended. But, Apple has fixed the “bug” starting from iOS 7.1 ......
Read more >
[Solved]-IOS - Location Update Interval - appsloveworld
There is no way to wake up the application after a given time interval to execute your code. You really have two options,...
Read more >
Receive messages in a Flutter app - Firebase - Google
On iOS, if the user swipes away the application from the app switcher, it must be manually reopened for background messages to start...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found