Reputation: 31
I am developing a expo react native standalone app . I am integating a expo background fetch in my mobile app project. I writing a code to start a background task every minute it's working properly in the android. if I am trying with iPad with the below configuration and code , it's not executing a task automatically. Can some one help on this?
Config changes in app.json
{
"expo": {
"ios": {
"infoPlist": {
"UIBackgroundModes": ["location", "fetch"]
}
}
}
}
Code for component
const triggerBackgroundFetch = async (taskName: string, taskFn: TaskManagerTaskExecutor, interval: number = 60 * 1) => {
try {
if (!TaskManager.isTaskDefined(taskName)) {
console.log('new task')
TaskManager.defineTask(taskName, taskFn);
}
else {
console.log('existing task')
}
const options = {
minimumInterval: interval // in seconds
};
await BackgroundFetch.registerTaskAsync(taskName, options);
await BackgroundFetch.setMinimumIntervalAsync(60);
} catch (err) {
console.log("registerTaskAsync() failed:", err);
}
}
const executeBackgroundTask = () => {
try {
// fetch data here...
const backendData = "task run time " + new Date(Date.now()).toLocaleString();
Alert.alert("Bg task")
console.log("Background Task: ", backendData);
//@ts-ignore
setStateFn(backendData);
return backendData
? BackgroundFetch.BackgroundFetchResult.NewData
: BackgroundFetch.BackgroundFetchResult.NoData;
} catch (err) {
console.log('err')
return BackgroundFetch.BackgroundFetchResult.Failed;
}
}
const triggerTask = async () => {
console.log('trigger background fetch')
await triggerBackgroundFetch('BackgroundTask1', executeBackgroundTask, 60);
// await unregisterBackgroundFetchAsync('PushNotificationBackgroundTask3');
};
iOS : 15.6.1
I am trying expo background fetch in the expo standalone app at iPad using windows machine. I am expecting to trigger a background fetch task automatically every interval.
Upvotes: 1
Views: 386