Please provide the following:
- SDK Version: 40
- Platforms: iOS
- Managed App not ejected.
I have been trying to get Background Fetch on iOS for a few weeks now but with no luck. I followed the steps in the docs correctly but have been unable to get it to run on iOS. I am including a snippet of my code below, if anyone could point out my issue it would be greatly appreciated.
startBackgroundTask below is called from the global scope in app.js
const startBackgroundTask = async () => {
TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
console.log('BackgroundTask running');
try {
// I am making a console.log and then calling an API here
return BackgroundFetch.Result.NewData;
} catch (err) {
console.log(`Error occured while running task: ${err.message}`, err);
return BackgroundFetch.Result.Failed;
}
});
const status = await BackgroundFetch.getStatusAsync();
if (status === BackgroundFetch.Status.Restricted || status === BackgroundFetch.Status.Denied) {
console.log('Background fetch is disabled.');
return;
}
try {
await BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
minimumInterval: INTERVAL,
stopOnTerminate: true,
startOnBoot: false,
});
await BackgroundFetch.setMinimumIntervalAsync(INTERVAL);
console.log('Background update task registered.');
} catch (err) {
console.log('Filed to register task for background.', err);
}
}
Result:
Console.log never prints and the task is never executed.