iphone - Update iOS Cordova WebView when app is in brackground -


i'm building app ios , android. app has javascript counter, updates time every seconds. when press home button in android , come back, counter right, updates when app on background, ios doesn't.

is there way make ios update webview on background?

sample js code update counter:

setinterval(){    $('#div').html(counter);    counter -= 1; }, 1000); 

i'm afraid tt's not possible in background mode on ios.

as @hanh-le mentioned ios stop (pause) app in 10 seconds moment send background.
native functionality (service) can keep running (like music playing, bluetooth running in background, etc). services can call javascript otherwise javascript stopped.

edit (added function of setinterval) if set interval this:

window.localstorage.setitem(     'counterinterval',      setinterval({         $('#div').html(counter);         counter -= 1;     }, 1000); ); 

you save timestamp on onpause() event , clear interval

function onpause() {     clearinterval(window.localstorage.getitem('counterinterval');     window.localstorage.setitem('pausetime', new date()); } 

and check elapsed time on onresume() event , update counter:

function onresume() {     var resumetime = new date(),         pausetime = window.localstorage.getitem('pausetime'),         elapsedtime = (resumetime.gettime() - pausetime.gettime()) / 1000;         //you can round elapsedtime if you'd         elapsedtime = math.round(elapsedtime);      //correct counter     $('#div').html(counter);     counter -= elapsedtime;          //set interval again until next `pause` event     window.localstorage.setitem(         'counterinterval',          setinterval({             $('#div').html(counter);             counter -= 1;         }, 1000);     ); } 

this save resources on background mode anyway...


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -