NSTimer Accuracy

后端 未结 1 1743
南笙
南笙 2021-01-15 12:28

I am currently working on an app that requires a sound file to be played at exact intervals, which are variable in duration.

I seem to remember being told that NSTim

相关标签:
1条回答
  • 2021-01-15 12:58

    In the first paragraph of Apple's NSTimer documentation you'll find this:

    A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds. If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer. Therefore, the actual time at which the timer fires potentially can be a significant period of time after the scheduled firing time.

    So you will definitely run (or play your sound, in your case) after your scheduled firing time, but not necessarily exactly at your time.

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