IOS UIWebView Javascript Timers

If the page loaded in the UIWebView contains a Javascript call to setInterval() , what is the behavior of this timer when the phone goes to sleep?

Is there a point in time when all timers stop?

Do timers restart when the phone wakes up? If so, does the timer start where it was paused, or started at 0?

+7
ios iphone ios7 ios8 uiwebview
source share
1 answer

WebKitโ€™s internal timer management is a little peculiar in general and, in particular, in iOS. They are registered in NSDefaultRunLoopMode mode, therefore, for example, when scrolling in the user interface, Javascript events are not triggered, but they are also not aggregated, as with regular timers ( NSTimer ).

To answer your question when the application process is paused, the timers are also paused, so they will not start until the process is paused. As soon as the process resumes for some reason (the user opened the application, background extraction, etc.), the Timers will resume their run and return to the relative point when the last tick should have been.

So, if you set a timer for every 10 seconds and close the application with t + 1 second, then open it again at t + 35 seconds, the timer will light up after 5 seconds; you will not hear retroactive ticks t + 10, t + 20 and t + 30 seconds.

Note. This is a timing management based on UIWebView / WebKitLegacy / technology; I am not very good at how WKWebView / WebKit2 / handles them.

+9
source share

All Articles