DispatchQueue.main.asyncAfter is inaccurate

后端 未结 1 1945
半阙折子戏
半阙折子戏 2021-01-05 04:39

I am trying to call a function after a delay. On iOS10 I am able to use Timer.scheduledTimer which does indeed call my closure after the given delay. However, on iOS9 I am u

相关标签:
1条回答
  • 2021-01-05 05:26

    asyncAfter is only guaranteed to wait at least as long as specified.

    You probably should still be using Timer if you want exact time intervals on iOS9.

    Timer.scheduledTimer(timeInterval: delay, 
                   target: self, 
                 selector: #selector(executeClosure), 
                 userInfo: nil, 
                  repeats: false)
    

    With executeClosure being a function that executes the last saved closure.

    0 讨论(0)
提交回复
热议问题