Re: Monitoring system time
Re: Monitoring system time
- Subject: Re: Monitoring system time
- From: Jerry Brace <email@hidden>
- Date: Mon, 30 May 2005 14:55:50 -0200
Thanks for that info!
Regarding this - what would be envolved in detecting when a computer comes out of sleep?
Further more - does anyone know how to code to awaken the computer at a set time?
Thanks
Jerry
On Monday, May 30, 2005, at 01:58PM, John Timmer <email@hidden> wrote:
>
>>> Could anyone give me information on the best way to monitor the
>>> system date/time and trigger an event?
>>> Basically I have some alarm records that have date and time stored -
>>> when the system date/time matches one of the records I need to fire
>>> an event.
>>
>> NSTimer is nice and all, but if 1) the computer sleeps 2) the user
>> changes the date in sys prefs 3) the computer adjusts the time for
>> daylight savings time then your NSTimers will need to be adjusted. So
>> you must watch for wake and date change notifications.
>
>This is a key point - the behavior of NSTimers when a system has been
>sleeping past the time they should have been triggered is undefined. What I
>tend to do is have any object that needs to perform an activity on a
>periodic basis register for sleep notifications and target its own periodic
>execution using NSObject's "performSelector:withObject:afterDelay:" method.
>When the system goes to sleep, clear this timer using
>"cancelPreviousPerformRequestsWithTarget:" and register for wake
>notifications. When you wake up, you can determine whether you should fire
>the events (if you've slept past them) or recalibrate your timer based on
>the new time.
>
>If you have a lot of objects of different classes that would need to fire
>off periodic activities, it might be worth making a singleton wake/sleep
>object to handle this, so that you can consolidate the code.
>
>JT
>
>
>_______________________________________________
>This mind intentionally left blank
>
>
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden