我选择在我正在开发的应用程序中更新后台位置。
在我的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。
在测试我的应用程序时,我发现只要我启用了后台位置更新,计时器就会在应用程序移动到后台时继续启动。难道这不应该发生吗?我能相信这个吗?
谢谢!
是的,你可以依赖它,只要计时器在你进入后台时正在运行