Expo BackgroundFetch 未执行

Dyl*_*ock 5 react-native expo

我试图在我的 Expo 应用程序的后台按设定的时间间隔运行一些代码。

我尝试过使用这里的解决方案:https://snack.expo.io/B1G39XcZr,但它似乎不起作用。我目前只是想让 console.log 正常工作。

BackgroundFetch.setMinimumIntervalAsync(60);
const taskName = 'test-background-fetch';

TaskManager.defineTask(taskName, () => {
  console.log('task run')
  return BackgroundFetch.Result.NewData;
});
Run Code Online (Sandbox Code Playgroud)

...

componentDidMount() {
  this.registerTaskAsync();
}

registerTaskAsync = async () => {
  await BackgroundFetch.registerTaskAsync(taskName);
  console.log('task registered');
};

Run Code Online (Sandbox Code Playgroud)

“任务已注册”会被打印,但“任务运行”不会被打印。