react-native-radar icon indicating copy to clipboard operation
react-native-radar copied to clipboard

No task registered for key BackgroundGeolocation

Open Saliheen opened this issue 1 year ago • 0 comments

I am getting No task registered for key BackgroundGeolocation for background location tracking.

Source Code

import {StyleSheet, Text, View} from 'react-native';
import React, {useEffect} from 'react';
import Radar from 'react-native-radar';


const App = () => {
  const doSetup = async () => {
    Radar.initialize('prj_test__________________');
    Radar.setUserId('1234567');
    Radar.setLogLevel("info");
  };

  const handlePermisions = async () => {
    // request foreground location permissions
    Radar.requestPermissions(false)
      .then(status => {
        // request background location permissions
        Radar.requestPermissions(true)
          .then(status => {
            // do something with status
          })
          .catch(err => {
            // optionally, do something with err
          });
      })
      .catch(err => {
        // optionally, do something with err
      });
  };


  const trackUserLocationInFoprground = async ()=> {
    Radar.trackOnce().then((result) => {  
      // console.log({result})
    }).catch((err) => { 
        console.log(err)
     });
  }

  const trackLocationInBackground = async () => {
    Radar.startTrackingContinuous();
  }


  const registerListeners = () => {
    Radar.on('clientLocation', (result:any) => {
      console.log(JSON.stringify({ event: 'clientLocation', result }, null, 2));
    });
    Radar.on('location', (result:any) => {
      console.log(JSON.stringify({ event: 'location', result }, null, 2));
    });
    Radar.on('events', (result:any) => {
      console.log(JSON.stringify({ event: 'events', result }, null, 2));
    });
    Radar.on('error', (err:any) => {
      console.error(JSON.stringify({ event: 'error', err }, null, 2));
    });
  };
  

  useEffect(() => {
    doSetup();
    handlePermisions();
    trackUserLocationInFoprground()
    trackLocationInBackground()
  }, []);

  return (
    <View style={styles.container}>
      <Text>Test Radar SDK</Text>
    </View>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {
    display: 'flex',
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});


Saliheen avatar Jun 11 '24 07:06 Saliheen