简体   繁体   中英

How many times will a repeating NSTimer fire when an application is restored to foreground?

Simple question:

I have a repeating NSTimer (let's say it repeats once every minute).

My application resigns active and the user locks the phone for 15 minutes. The phone is asleep, I am not doing any secret tricks to keep it active like playing an inaudible sound or anything.

When the user unlocks the phone and the application is restored to the foreground, does my timer fire 1 time or 15 times? I believe the answer is 1, I just want to make sure.

Thanks!

Yes. The Timing programming topic says

If the firing time is delayed so far that it passes one or more of the scheduled firing times, the timer is fired only once for that time period; the timer is then rescheduled, after firing, for the next scheduled firing time in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM