2017-09-01 112 views
0

我试图在应用程序暂停时执行一些功能。我用 -如何在应用程序未在Cordova中运行时进行后台处理?

https://github.com/katzer/cordova-plugin-background-mode

它完美,当应用程序正在运行,当杀应用程序被停止工作。然后,我使用 - https://github.com/katzer/cordova-plugin-local-notifications

它会在应用程序被杀时发出通知,但除非应用程序正在运行,否则我无法处理它的任何事件。有人在一段时间后杀死应用程序时是否会尝试像ajax调用一样?在应用程序未运行时是否有其他回购协议可以提供后台服务?

(推送通知是不是在这种情况下,我的解决方案)

感谢。

+0

当应用程序未运行时,本地通知将不起作用。 –

回答

0

您正在寻找这个插件:https://ionicframework.com/docs/native/background-fetch/它允许您在用户的“活动”时间(如Apple定义的)​​时间内在后台运行30s代码。

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

    backgroundFetch.configure(config) 
    .then(() => { 
     console.log('Background Fetch initialized'); 
     //Your code to be repeatedly executed here 

     this.backgroundFetch.finish(); 

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

对我来说,文档是不明确的,但传递给then的方法就是所谓的在任何时间间隔OS在醒来。