Take the 2-minute tour ×

I have a timer app which uses a NSTimer to track minutes. How can I keep the timer going, even when the device is put into sleep mode? Thanks!

share|improve this question
You need to update your question with information about why you think you need the timer to keep going when the device is asleep. Most likely there is a better solution but it depends on what you need this for. –  rmaddy Nov 24 '13 at 17:27
add comment

2 Answers

up vote 1 down vote accepted

Adjust After Wake Notification

Scheduled NSTimer instances will halt during sleep. Your application needs to respond to the NSWorkspace's wake notification and adjust its timers.

If you do not respond to wake notifications, your timers will resume but without accounting for the time spent asleep.

See Apple's technical note QA1340 Registering and unregistering for sleep and wake notifications for getting the appropriate notifications.


Consider this situation:

  • Create a timer to trigger in 5 minutes
  • Wait 1 minute
  • Put the computer to sleep for an hour
  • Wake the computer
  • The timer resumes upon waking
  • The timer triggers 4 minutes after waking

From the timer's perspective, five minutes has passed by. Note the language used by NSTimer, it uses relative durations rather than absolute times, scheduledTimerWithTimeInterval:invocation:repeats:.

share|improve this answer
What happens if I don't respond to wake notifications, as I am doing now? –  PanicDev Nov 24 '13 at 16:54
Your timer will resume but not account for the time spent asleep. –  Graham Miln Nov 25 '13 at 11:30
Could I use something like NSDate to track and add the time spent asleep? –  PanicDev Nov 25 '13 at 15:01
Yes, NSDate is the recommended way to get the current date and time. You will need to reschedule your timer after wake. –  Graham Miln Nov 25 '13 at 19:01
add comment

Take a look at this class, which handles sleep/wake for you with the "Hourglass" behavior: https://github.com/jmah/MyLilTimer

share|improve this answer
add comment

Your Answer


