首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >离子backgroundFetch配置不更新

离子backgroundFetch配置不更新
EN

Stack Overflow用户
提问于 2020-03-04 17:20:04
回答 1查看 840关注 0票数 0

我正在开发一个带有电容的离子应用程序。我希望我的应用程序能够在终止后执行后台任务。如果我正确地阅读了文档,通过设置

代码语言:javascript
复制
stopOnTerminate: false

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

代码语言:javascript
复制
    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窗口中看到它没有更新stopOnTerminate值。

代码语言:javascript
复制
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
    }

我还需要做些什么才能改变缺省值吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-05 11:22:11

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

代码语言:javascript
复制
import BackgroundFetch from 'cordova-plugin-background-fetch';

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

代码语言:javascript
复制
        // 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中被更改。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60531475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档