离子 backgroundFetch 配置未更新

ionic backgroundFetch config not updating

我正在构建一个带电容器的离子应用程序。我希望我的应用程序可以在终止后执行后台任务。如果我正确阅读文档,这应该可以通过设置

stopOnTerminate: false

我创建了一个空白应用程序,我可以在上面测试 backgroundFetch 插件并使用了以下代码。

    const config: BackgroundFetchConfig = {
      stopOnTerminate: false, // Set true to cease background-fetch from operating after user "closes" the app. Defaults to true.
    };

    this.backgroundFetch.configure(config)
        .then(() => {
          console.log('Background Fetch initialized');


          this.backgroundFetch.finish();

        })
        .catch(e => console.log('Error initializing background fetch', e));

    this.backgroundFetch.start();

然而,当我构建应用程序并使用电容器打开它时,我可以在 android studio logcat window 中看到它没有更新 stopOnTerminate 值

com.example.app D/TSBackgroundFetch: {
      "taskId": "cordova-background-fetch",
      "isFetchTask": true,
      "minimumFetchInterval": 15,
      "stopOnTerminate": true, // This should have changed to false
      "requiredNetworkType": 0,
      "requiresBatteryNotLow": false,
      "requiresCharging": false,
      "requiresDeviceIdle": false,
      "requiresStorageNotLow": false,
      "startOnBoot": false,
      "forceAlarmManager": false,
      "periodic": true,
      "delay": -1
    }

我还需要做些什么才能更改默认设置吗?

设法使用不同的方式导入 BackgroundFetch 插件使其工作

import BackgroundFetch from 'cordova-plugin-background-fetch';

然后在配置选项中我需要添加 enableHeadless 以使其正常工作

        // Your background-fetch handler.
        const fetchCallback = (taskId) => {
            console.log('[js] BackgroundFetch event received: ', taskId);
            // Required: Signal completion of your task to native code
            // If you fail to do this, the OS can terminate your app
            // or assign battery-blame for consuming too much background-time
            BackgroundFetch.finish(taskId);
        };

        const failureCallback = (error) => {
            console.log('- BackgroundFetch failed', error);
        };

        BackgroundFetch.configure(fetchCallback, failureCallback, {
            minimumFetchInterval: 15, // <-- default is 15
            stopOnTerminate: false,
            enableHeadless: true // <-- Added this line
        });

现在正在 android studio

中更改配置