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

Cannot use postTemplate to send information to provided url

Open dakotatyrrell opened this issue 4 years ago • 1 comments
trafficstars

Your Environment

  • Plugin version: v0.6.6
  • Platform: iOS
  • OS version: iOS 14.4
  • Device manufacturer and model: Apple iPhone X
  • Running in Simulator: No
  • React Native version: 0.63.4
  • Plugin configuration options:
BackgroundGeolocation.configure({
  desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
  stationaryRadius: 50,
  distanceFilter: 500,
  notificationsEnabled: false,
  debug: false,
  startOnBoot: true,
  stopOnTerminate: false,
  locationProvider: BackgroundGeolocation.DISTANCE_FILTER_PROVIDER,
  interval: 10000,
  fastestInterval: 5000,
  activitiesInterval: 10000,
  stopOnStillActivity: false,
  maxLocations: 10,
  syncThreshold: 5,
  url: 'https://example.com', // Actual website here in full project
  httpHeaders: {
    'Accept': 'application/json',
    'Content-Type': 'multipart/form-data'
  },
  // customize post properties
  postTemplate: {
    Email: '[email protected]',
    UserID: 'fakeID',
    PushKey: 'fakePushKey',
    latitude: '@latitude',
    longitude: '@longitude',
    i_Meta_Data: 1
  }
});

BackgroundGeolocation.on('location', (location) => {
  BackgroundGeolocation.startTask(taskKey => {
    console.log('ON location: ', location);
    BackgroundGeolocation.endTask(taskKey);
  });
});

BackgroundGeolocation.on('stationary', (stationaryLocation) => {
  // handle stationary locations here
  console.log('[INFO] BackgroundGeolocation service is stationary');
});

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

BackgroundGeolocation.on('start', () => {
  console.log('[INFO] BackgroundGeolocation service has been started');
  BackgroundGeolocation.startTask(taskKey => {
    console.log('ON location: ', location);
    BackgroundGeolocation.endTask(taskKey);
  });
});

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

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');
  this.setState({
    isBackground: true,
  });
});

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

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

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);
});
  • Link to your project: N/A

Context

The postTemplate information is never sent to the url provided in the configuration of BackgroundGeolocation. Additionally, tasks are never ran when the app is terminated even though stopOnTerminate is set to false.

Expected Behavior

The postTemplate should be sent to the url provided in the configuration of BackgroundGeolocation.

Actual Behavior

There is no indication that the postTemplate information is being sent to the provided url on the app's side. The back end does not claim to have received any information from the app.

Possible Fix

Steps to Reproduce

  1. Define a BackgroundGeolocation configuration as shown above.
  2. Run the task based on location updates using BackgroundGeolocation.on('location')
  3. Check for an indication that information was sent on both the front end and the back end.

Context

Trying to send location information to a back-end, where it is then sent into a database. While it is possible to send information through BackgroundGeolocation.on('location'), this does not allow for the sending of location information when the app is terminated.

Debug logs

dakotatyrrell avatar Feb 26 '21 17:02 dakotatyrrell

This plugin seems having an issue with iOS. Soon I'll investigate into it.

darron1217 avatar Mar 08 '21 01:03 darron1217