background location doesn't work and throw error TaskManager.defineTask must be called during initialization phase!

Please provide the following:

  1. SDK Version:36.0.0
  2. Platforms(Android/iOS/web/all):iOs

Steps to Reproduce

1-TaskManager.defineTask() in global scope in app entry file (App.js)
2- Location.startGeofencingAsync(‘locationTask’,[
{
“identifier”: “A”,
“latitude”: lat,
“longitude”: lng,
“radius”:100,
“notifyOnEnter”: true,
“notifyOnExit”: true,

}
]) in app entry file (App.js)
3-Log output

Expected Behavior

Background geofencing should work exactly as if the app were active.

Actual Behavior

error which says
TaskManager: Task “locationTask” has been executed but looks like it is not defined. Please make sure that “TaskManager.defineTask” is called during initialization phase.

Reproducible Demo

 export default function App(props) {
 var lat=0;
 var lng=0;
 users=firebase.auth().currentUser;
if(users !=null){
firebase.database().ref('mgnUsers/'+firebase.auth().currentUser.uid).once('value',(snap)=>{ 
lat= snap.val().latitude;
lng= snap.val().longitude;
   })
  try{
   if(!(lat==='0'&& lng==='0')){
    Location.startGeofencingAsync('locationTask',[
        {
            "identifier": "A",
            "latitude": lat,//await AsyncStorage.getItem('latPoint'),
            "longitude": lng, //await AsyncStorage.getItem('lngPoint'),
            "radius":100,
            "notifyOnEnter": true,
            "notifyOnExit": true,
           
        }
       ])
       }
     }
    //  }//end try
    catch(error){
    }//end catch
   }
  }

     TaskManager.defineTask('locationTask', async ({ data, error }) => {




     }); 

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.