I am having an issue with log box and expo i tried to fix it but it was to no avail. here's the code. a little added comment: i am using a development server on android. i am trying to schedule a background task:
import * as BackgroundFetch from "expo-background-fetch";
import * as TaskManager from "expo-task-manager";
import { useState, useEffect } from "react";
import { fetchPrayerTimesFunction } from "../utils/FetchPrayerTimes";
const BACKGROUND_FETCH_TASK = "background-fetch";
TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
try {
const receivedNewData = await fetchPrayerTimesFunction();
return receivedNewData
? BackgroundFetch.BackgroundFetchResult.NewData
: BackgroundFetch.BackgroundFetchResult.NoData;
} catch (error) {
return BackgroundFetch.BackgroundFetchResult.Failed;
}
});
export default function BackgroundFetchFunction() {
const [isRegistered, setIsRegistered] = useState(false);
const [status, setStatus] =
useState<BackgroundFetch.BackgroundFetchStatus | null>(null);
async function registerBackgroundFetchAsync() {
return BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
minimumInterval: 60 * 15, // 15 minutes
stopOnTerminate: false, // android only,
startOnBoot: true, // android only
});
}
const checkStatusAsync = async () => {
const status = await BackgroundFetch.getStatusAsync();
const isRegistered = await TaskManager.isTaskRegisteredAsync(
BACKGROUND_FETCH_TASK
);
setStatus(status);
setIsRegistered(isRegistered);
};
useEffect(() => {
registerBackgroundFetchAsync();
checkStatusAsync();
toggleFetchTask();
}, []);
const toggleFetchTask = async () => {
if (!isRegistered) {
await registerBackgroundFetchAsync();
}
checkStatusAsync();
};
}
I was expecting for the background function to work but unfortunately it gave me a logbox error not sure why it did that as i have no console logs in there (unless im blind and i missed one)