Question on NSTimer

Discussion in 'iPhone/iPad Programming' started by iamakimmer, Apr 21, 2009.

  1. macrumors newbie

    Joined:
    Apr 21, 2009
    #1
    Hi,

    Can someone point me in the right direction? I want to trigger an method when it hits a certain dynamic time that I set. For example at 9:00 PM today I want to call a method. The app will be running continuously. Would NSTimer be the best option for this? The only question I have with NSTimer would be what would my interval be, as the examples I've seen on NSTimer are intervals such as seconds or minutes. Is there a way to send NSTimer a future date?

    Thanks for your help!!
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Just set the interval on the timer to be the future date minus the current date (both in seconds). This is easy to do with -[NSDate timeIntervalSinceDate:]
     
  3. macrumors regular

    Joined:
    Apr 9, 2009
    #3
    or just use
    Code:
    - (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
    of NSTimer

    but in any case, I would be interested in what you are trying to do, since I can't imagine an app so great the user would keep it running all the time :D
     

Share This Page