Re: Synchronize timer with internal clock
Re: Synchronize timer with internal clock
- Subject: Re: Synchronize timer with internal clock
- From: John Timmer <email@hidden>
- Date: Fri, 14 Mar 2003 19:41:32 -0500
Yeah, didn't work for me, either. What I'm currently trying is the
following:
According to Apple's Docs, the timer passes itself as the argument to its
selector. So, in theory, your method can have an argument of
(id)minuteTimer and have the timer handed to it. Somewhere in your method,
you can put the following catch:
if ([now secondOfMinute] != 0) {
NSLog( @"compensating for time shift");
[minuteTimer invalidate];
minuteTimer = [[NSTimer scheduledTimerWithTimeInterval:(60-[now
secondOfMinute]) target:self selector:@selector(timeSynch) userInfo:nil
repeats:NO] retain];
}
This should keep things current. Using the same line of code anywhere else
in your object should also work to get you running in the first place, as
long as you create "now" as an NSCalendarDate object..
Cheers,
John
>
>
I've tried the following code:
>
>
NSCalendarDate *now = [NSCalendarDate calendarDate];
>
NSCalendarDate *run = [now dateByAddingYears:0 months:0 days:0
>
hours:0 minutes:1 seconds:(60-[now secondOfMinute])];
>
>
timer = [[NSTimer alloc] initWithFireDate:run
>
interval:60
>
target:self
>
>
selector:@selector(timerAction:)
>
userInfo:nil
>
repeats:YES];
>
>
This is not working for me (10.2.4) - a NSLog of "run" before and
>
[timer fireDate] after the timer is initialized shows
>
the right date/time. [timer isValid] returns 1. The timerAction is
>
never executed. A manual [timer fire] works.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.