正如我从文档中了解到的那样,您启动了一个默认任务(当您的应用程序最小化时运行)以及可选的无头任务(当您的应用程序终止时运行)。像这样:
//configure normal background task, set time interval as 15 minutes.
BackgroundFetch.configure({
minimumFetchInterval: 15
}, async (taskId) => {
console.log("[BackgroundFetch] taskId: ", taskId);
// Finish, providing received taskId.
BackgroundFetch.finish(taskId);
}, async (taskId) => {
BackgroundFetch.finish(taskId);
});
let MyHeadlessTask = async (event) => {
let taskId = event.taskId;
let isTimeout = event.timeout;
if (isTimeout) {
BackgroundFetch.finish(taskId);
return;
}
console.log('[BackgroundFetch HeadlessTask] start: ', taskId);
// some task..
BackgroundFetch.finish(taskId);
}
// Register your BackgroundFetch HeadlessTask, which also runs every 15 minutes, because of the above configuration of minimumFetchInterval.
BackgroundFetch.registerHeadlessTask(MyHeadlessTask);
我想要的是能够使用 minimumFetchInterval 配置仅注册一个无头任务。像这样的东西:
BackgroundFetch.registerHeadlessTask(MyHeadlessTask, {
minimumFetchInterval: 15
});
但我知道registerHeadlessTask
不接受配置输入。还有其他方法吗?