What happens to JavaScript execution (settimeout, etc.) when iPhone/Android goes to sleep?

后端 未结 4 2023
广开言路
广开言路 2020-12-13 02:25

I have a jQuery Mobile web app which targets iOS and Android devices. A component of the application is a background task, which periodically checks for a.) changes to local

4条回答
  •  死守一世寂寞
    2020-12-13 02:53

    You can use this class github.com/mustafah/background-timer based on @jlafay answer , where you can use as follow:

    coffeescript

    timer = new BackgroundTimer 10 * 1000, ->
        # This callback will be called after 10 seconds
        console.log 'finished'
    
    timer.enableTicking 1000, (remaining) ->
        # This callback will get called every second (1000 millisecond) till the timer ends
        console.log remaining
    
    timer.start()
    

    javascript

    timer = new BackgroundTimer(10 * 1000, function() {
        // This callback will be called after 10 seconds
        console.log("finished");
    });
    
    timer.enableTicking(1000, function(remaining) {
        // This callback will get called every second (1000 millisecond) till the timer ends
        console.log(remaining);
    });
    
    timer.start();
    

    Hope it helps, Thank you ...

提交回复
热议问题