我使用NSTimer
每24小时调用一次方法,当app首次启动时,计时器首先被初始化,我将间隔设置为86400
,如下所示:
-(NSTimer*)todayTimesTimer{
NSDate *now=[NSDate date];
if (!_todayTimesTimer) {
_todayTimesTimer=[[NSTimer alloc] initWithFireDate:now interval: 86400 target: self selector:@selector(businessMethod) userInfo:nil repeats:YES];
}
return _todayTimesTimer;
}
正如我所说,首次启动应用程序时首次启动计时器,如下所示:
- (void) viewDidLoad {
[self launchTodayTimesCalculationTimer];
}
和launchTodayTimesCalculationTimer
定义如下:
-(void)launchTodayTimesCalculationTimer{
NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:self.todayTimesTimer forMode: NSRunLoopCommonModes];
}
问题是,当应用在后台时,方法businessMethod
没有调用,是否有NSTimer
的运行模式在后台调用选择器?如果不是当应用程序在后台时运行选择器的可能想法是什么?提前谢谢。