我为mac写了一个简单的应用程序,使用系统时间来计算一些数据,我想在时钟到达12:00的时候运行一个特定的例程
有没有什么系统api可以解决这个问题?
我该怎么做呢?
实际上,我在我的应用程序中有一个状态栏项目,显示任何选定日历中的当前日期,如公历和伊斯兰,我希望这个值将与系统时间同步
发布于 2013-02-22 01:44:40
如果您的例程是object的- routine:(NSTimer *)timer方法
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; // Current time
NSTimeInterval then = ((int)now + 86400) % 86400; // Next 12am
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:then];
NSTimer *timer = [[NSTimer alloc] initWithFireDate:date interval:86400 target:object @selector(routine:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];https://stackoverflow.com/questions/15000430
复制相似问题