未在后台调用iOS选择器

未在后台调用iOS选择器,ios,objective-c,cocoa-touch,ios7,nstimer,Ios,Objective C,Cocoa Touch,Ios7,Nstimer,我使用NSTimer每24小时调用一个方法,当应用程序首次启动时,计时器首先初始化,我将间隔设置为86400,如下所示: -(NSTimer*)todayTimesTimer{ NSDate *now=[NSDate date]; if (!_todayTimesTimer) { _todayTimesTimer=[[NSTimer alloc] initWithFireDate:now interval: 86400 target: self selector:@selec

我使用
NSTimer
每24小时调用一个方法,当应用程序首次启动时,计时器首先初始化,我将间隔设置为
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];
}
-(void)launchTodayTimesCalculationTimer{
 NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:self.todayTimesTimer forMode: NSRunLoopCommonModes];
}
正如我所说,计时器在应用程序首次启动时首先初始化,如下所示:

-(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];
}
-(void)launchTodayTimesCalculationTimer{
 NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:self.todayTimesTimer forMode: NSRunLoopCommonModes];
}
launchTodayTimeCalculationTimer
的定义如下:

-(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];
}
-(void)launchTodayTimesCalculationTimer{
 NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:self.todayTimesTimer forMode: NSRunLoopCommonModes];
}

问题在于,当应用程序位于后台时,不会调用方法
businessMethod
,是否存在在后台调用选择器的
NSTimer
运行模式?如果不是,当应用程序处于后台时运行选择器的可能想法是什么?提前谢谢。

计时器启动时,你想做什么?没有在特定时间启动应用程序的后台模式。是否已启用项目设置->目标->功能->后台模式-?@Paulw11我不想在特定时间启动应用程序,我想在应用程序处于后台时调用方法抱歉,我应该澄清-我不是说在前台启动-即使在后台执行的情况下,你的应用程序通常会由iOS重新启动-不在前台的应用程序可以随时卸载,如果各种后台模式需要,它们会重新启动。你想做什么-iOS应用程序编程指南中描述了特定的后台模式。你不能这样做。您可以发布本地通知,提示用户启动您的应用程序。您可以尝试后台刷新模式,并检查是否已经24小时,但您无法安排应用程序在特定时间运行。