• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Synchronize timer with internal clock
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Synchronize timer with internal clock (From: Frank Fenn <email@hidden>)

  • Prev by Date: Re: UI responsiveness
  • Next by Date: Re: Saving data to a file
  • Previous by thread: Re: Synchronize timer with internal clock
  • Next by thread: Re: Synchronize timer with internal clock
  • Index(es):
    • Date
    • Thread