我正在开发一个iPhone应用程序,当应用程序处于后台或前台时,它应该每15分钟更新一次gps位置并将其发送到我的服务器。
我正在使用NSTimer,它每秒调用一个方法来做几件事(我的方法只每15分钟更新一次) 我在我的ViewController中尝试使用它来保持我的Timer在后台运行:
(...)
TimerTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{
}];
CurrentTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(timerTicked:) userInfo: nil repeats: YES];
(...)
但问题是,大约10分钟后,当应用程序处于后台时,我的计时器似乎停止了。
有可能做得对吗?
谢谢
答案 0 :(得分:3)
您可以在NSTimer
中使用AppDelegate
,也可以添加NSNotification
。两者都很有用。
请查看以下链接: -
How do I get a background location update every n minutes in my iOS application?