mauron85 / react-native-background-geolocation

Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
Apache License 2.0
1.34k stars 565 forks source link

iOS Simulator stop to receive location update when app is killed #510

Open paolosantarsiero opened 4 years ago

paolosantarsiero commented 4 years ago

Your Environment

Context

Expected Behavior

Actual Behavior

Possible Fix

Steps to Reproduce

1. 2. 3. 4.

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();

},[])

ferasabufares commented 4 years ago

@paolosantarsiero

Did you Find any solution

i have the same problem when ios simulator or real device app is on the background location not updating

paolosantarsiero commented 4 years ago

Nothing, i try to switch provider to distance filter provider but the updates is really slow and not every time uodates received

jeronimo commented 4 years ago

Try to switch locationProvider to RAW_PROVIDER as ACTIVITY_PROVIDER is Android only.

manuja124140E commented 4 years ago

@paolosantarsiero

Did you find any solution, I have the same problem

mehmetsalihakcan commented 4 years ago

Hello friends ,Did you find any solution, I have the same problem?

Adigezalov commented 4 years ago

I have the same problem. When minimizing the application on iOS, geolocation is paused (RCTBackgroundGeoLocation paused). And when you kill the application, it turns off altogether

caiquebb commented 4 years ago

This worked for me:

https://github.com/transistorsoft/react-native-background-geolocation/blob/master/help/INSTALL-IOS-AUTO.md#configure-background-capabilities

Don,t forget to do that too: https://github.com/transistorsoft/react-native-background-fetch/blob/master/docs/INSTALL-AUTO-IOS.md#configure-background-capabilities

Ntobon commented 3 years ago

This worked for me:

https://github.com/transistorsoft/react-native-background-geolocation/blob/master/help/INSTALL-IOS-AUTO.md#configure-background-capabilities

Don,t forget to do that too: https://github.com/transistorsoft/react-native-background-fetch/blob/master/docs/INSTALL-AUTO-IOS.md#configure-background-capabilities

@caiquebb,

Which task id did you registered as "Permitted background task scheduler identifiers" ?

Thanks in advance for your help.

luisfuertes commented 3 years ago

+1

bodrius commented 2 years ago

the same problem