2017-09-01 105 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在醒來。