undefinedfix
Sign in

The time interval of setinterval in IOS

twldb edited in Thu, 30 Jun 2022

Yonsetinterval makes a countdown function. It executes the code every 10ms. There is no problem in windows, MAC and Android, but in IOS browser, the time interval becomes larger. The time difference between the two codes is 8-12ms on windows, MAC and Android, but it becomes 20-60ms on IOS

The picture below shows the time interval of IOS acquisition

The picture below is the correct time interval

clipboard.png

var d1 = new Date().getTime();
 var timecount=setInterval(function(){
    var d2 = new Date().getTime();
    console.log(d2-d1);
    d1 = d2;
 
},10);

How to solve this problem

2 Replies
pazhitnov
commented on Fri, 01 Jul 2022

The timer is never accurate, which only depends on the execution time of your macro task. If the execution time of the intermediate synchronization JS is too long, the timer trigger will be affected.

alincocio
commented on Fri, 01 Jul 2022

Thank you, I remember that the error of foxes is 13ms. Please see the disadvantages and solutions of setinterval in this article

lock This question has been locked and the reply function has been disabled.