If your application is being used as a homescreen web application, you’ll find yourself in a sorry state. Of course, any web app can be converted into a home screen app by the user, so I guess technically this affects anyone making a remote web application. This bug is easily reproduced by simply calling setTimeout(callback, 1) or requestAnimationFrame(callback) via some button or event. When you first open your application, you’ll notice all timing functions are working fine. However if you lock your phone and then unlock to return to your application, you’ll see none of the timing functions can call callbacks anymore. They are simply broken at a native level. There is no reset, no bringing your application back to life, it’s a kill it and restart situation.
Radar Bug Report: http://www.openradar.me/radar?id=5895945212395520
setInterval are evil and not precise…
- both have a delay of various milliseconds http://www.andrewduthie.com/post/a-self-correcting-setinterval-alternative/
- both are very resource intensive as they execute several times every second.
A new alternative is
requestAnimationFrame. it’s less resource=intensive, does not slow down other stuff and it is disabled on page blur.
This makes it the perfect substitute for a modern
So I wrote this functions:
This functions use
requestAnimationframe to check if the time is passed based on the elapsed Time calculated from
Date.now. The time passed is more precise than the native functions and theoretically less resource intensive. Another advantage/disadvantage(depends) is that the functions are not executed on page blur.
Good for: animations, visual effects
Bad for: timers, clock
/* to clear