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
Post a Comment