transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.63k stars 425 forks source link

Background action working only for 30 second in iOS #2033

Closed Skvitthani closed 2 months ago

Skvitthani commented 4 months ago

Plugin version: 2.11.0 Platform: iOS OS version: 14.4 Device manufacturer / model: Apple iPhone 12 React Native version: 0.72.7 Plugin config BackgroundGeolocation.ready({ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 25, stopTimeout: 10, debug: false, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, stopOnTerminate: false, startOnBoot: true, url: "http://yourserver.com/locations", batchSync: false, autoSync: true, disableMotionActivityUpdates : true, headers: { "X-FOO": "bar" }, }, (state) => { if (!state.enabled) { BackgroundGeolocation.start(function() { console.log("- Start success"); }); } });

BackgroundGeolocation.onLocation(({ coords }) => {
  try {
    if (coords) {
      const { latitude, longitude} =
        coords;
        reduxActions.location.updateLocation(
          latitude,
          longitude,
        );
    }
  } catch (error: unknown) {
    console.log('error',error)
  }
});

export async function startLocationUpdateAsync() { try { await BackgroundService.start(veryIntensiveTask, options); } catch (error) { console.log('ERROR :: startLocationUpdateAsync :: ', error) } }

const veryIntensiveTask = async (taskDataArguments: any) => { await new Promise(async resolve => { try{ if(Platform.OS == 'ios'){ BackgroundGeolocation.ready({ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 25, stopTimeout: 10, debug: false, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, stopOnTerminate: false, startOnBoot: true, url: "http://yourserver.com/locations", batchSync: false, autoSync: true, disableMotionActivityUpdates : true, headers: { "X-FOO": "bar" }, }, (state) => { if (!state.enabled) { BackgroundGeolocation.start(function() { console.log("- Start success"); }); } });

BackgroundGeolocation.onLocation(({ coords }) => {
  try {
    if (coords) {
      const { latitude, longitude} =
        coords;
        reduxActions.location.updateLocation(
          latitude,
          longitude,
        );
    }
  } catch (error: unknown) {
    console.log('error',error)
  }
});

}else{ Geolocation.watchPosition( (location: any)=> { reduxActions.location.updateLocation( location.coords.latitude, location.coords.longitude, ); }, error => {}, { enableHighAccuracy: false, maximumAge: 0, distanceFilter: 30, }, ); } }catch(e){console.log('e',e)} }) };

Expected Behavior

It Should work in the background until the app gets killed in iOS only.

Actual Behavior

It works only for 30 seconds in the background.

christocracy commented 4 months ago

Please learn to syntax highlight fenced codeblocks

christocracy commented 4 months ago

Also, when testing, go outside for a walk with a real device for at least 1km.

see wiki “Philosophy of Operation” and “Debugging”.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.