NSTimer 在后台模式下工作 - 但它不应该不工作吗?



我选择在我正在开发的应用程序中更新后台位置。

在我的LocationManager类中,我有一个方法看起来像这样:

- (void)beginUpdateTimer
{
    [self.updateTimer invalidate];
    self.updateTimer = [NSTimer timerWithTimeInterval:ForceUpdateDuration
                                               target:self
                                             selector:@selector(updateWithLastKnownLocation)
                                             userInfo:nil
                                              repeats:NO];
    NSRunLoop *runloop = [NSRunLoop currentRunLoop];
    [runloop addTimer:_updateTimer forMode:NSRunLoopCommonModes];
}

方法-updateWithLastKnownLocation可能会再次调用beginUpdateTimer。

在测试我的应用程序时,我发现只要我启用了后台位置更新,计时器就会在应用程序移动到后台时继续启动。难道这不应该发生吗?我能相信这个吗?

谢谢!

是的,你可以依赖它,只要计时器在你进入后台时正在运行

相关内容

最新更新