Reputation:
I am trying to find a means of scheduling a method call on a daily interval at a specified time. For example, every morning at 3am.
NSTimer
and similar functionality is provided that allows you to schedule tasks after a specified duration but it would be nice if there is a way to schedule at a time, rather than after a time period expires.
Can anyone give me some advice on how to do that?
Upvotes: 0
Views: 351
Reputation: 45180
It's always nice to look through class docs before asking a question on Stack Overflow. NSTimer documentation says there's a method:
- (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
Let the date
be the next morning 3am and the time interval - 24hrs.
Upvotes: 7