running background tasks in react-native-background-fetch

155 Views Asked by At

im using a bare expo project and i need to mute the phone at certain times entered by user . however the background task doesnt seem to work . I tested the app in development by simulating the job and then it was fine but now in production it doesnt seem to be working,

const initTask = async () => {
    try {
      const backgroundFetchConfig = {
        minimumFetchInterval: 15, // In minutes
        startOnBoot: true,
        stopOnTerminate: false,
        enableHeadless: true,
      };
  const status = await BackgroundFetch.configure(backgroundFetchConfig, async (taskid) => { const res = await handleBackgroundFetch(taskid); console.log("res ", res) }, (taskId) => { BackgroundFetch.finish(taskId) });
  return status
} catch (e) {
  console.log("init ", e)
  return e
}

}

 useEffect(() => {

    initTask().then(s => console.log("status", s)).catch(e => console.log("u init", e))
    // Clean up the background fetch when the component unmounts

  }, []);

As u can see im defining the task and running it but it doesnt seem to be working , any help would be appreciated, i can provide more details if required

0

There are 0 best solutions below