Closed jcschmittmouts closed 2 weeks ago
Debugging it I realized that the tasks are being called correctly. But inside my task there's a http request to my backend server that is not exectuted for some reason and all those requests are being called at the same time when I put my app in foreground. Anybody who knows why this occurs? There's a way to avoid this behavior?
can you please help me. I want to display notification after every 15 mins even when the app is terminated or closed. It works fine when the app is open but it doesn't work when the app is closed or terminated. ` async function onDisplayNotification() { // Request permissions (required for iOS) await notifee.requestPermission() console.log("Notification run")
// Create a channel (required for Android)
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
});
// Display a notification
await notifee.displayNotification({
title: 'Notification Title',
body: 'Main body content of the notification',
android: {
channelId,
// smallIcon: 'name-of-a-small-icon', // optional, defaults to 'ic_launcher'.
// pressAction is needed if you want the notification to open the app when pressed
pressAction: {
id: 'default',
},
},
});
}
const addEvent = (taskId) => { const timestamp = new Date().toLocaleString(); setEvents((prevEvents) => [...prevEvents, { taskId, timestamp }]); };
const initBackgroundFetch = async () => { const onEvent = async (taskId) => { console.log('[BackgroundFetch] Task:', taskId); onDisplayNotification() await addEvent(taskId); BackgroundFetch.finish(taskId); };
const onTimeout = async (taskId) => {
console.warn('[BackgroundFetch] TIMEOUT Task:', taskId);
BackgroundFetch.finish(taskId);
};
const status = await BackgroundFetch.configure(
{ minimumFetchInterval: 15,
startOnBoot:true,
stopOnTerminate:false, enableHeadless:true }, onEvent, onTimeout, );
console.log('[BackgroundFetch] Configure Status:', status);
};
useEffect(() => { initBackgroundFetch(); onDisplayNotification() }, []); `
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
react-native -v
): 0.71.12Expected Behavior
The expected behavior is to execute the task every 10 minutes (TOTAL_TIMER = 10) even if my app is not in foreground.
Actual Behavior
The task is not running in background, but if I put my app in foreground, all those tasks that was not ran are being called at the same time.
Steps to Reproduce
Configure the BackgroundFetch as shown in the Plugin config section above.
Context
Run a task every 10 minutes even if my app is not in foreground.