iOS选择器未在后台调用

时间:2014-08-31 09:29:28

标签: ios objective-c cocoa-touch ios7 nstimer

我使用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的运行模式在后台调用选择器?如果不是当应用程序在后台时运行选择器的可能想法是什么?提前谢谢。

0 个答案:

没有答案