iOS 在 600 秒后终止我的后台任务
我正在开发一个应用程序,需要后台任务每 30 分钟更新一次位置。 我尝试过使用 NStimer 并每分钟更新一次并且它有效(它花了 2 个小时工作)。然而,当我将其设置为 30 分钟时,iOS 在 10 分钟后终止了我的应用程序。
日志显示:
Sun Oct 16 11:29:47 unknown SpringBoard[32] <Warning>: MyApp[315] has active assertions beyond permitted time:
{(
<SBProcessAssertion: 0xbb34040> identifier: UIKitBackgroundCompletionTask process: MyApp[315] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:315 preventSuspend preventIdleSleep
)}
Sun Oct 16 11:29:47 unknown SpringBoard[32] <Warning>: Forcing crash report of WhereAreYouReg[315]...
Sun Oct 16 11:29:48 unknown SpringBoard[32] <Warning>: Finished crash reporting.
我的后台任务是用以下代码启动的:
backgroundTaskIdentifier = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
// If you're worried about exceeding 10 minutes, handle it here
}];
theTimer=[NSTimer scheduledTimerWithTimeInterval:30*60.0
target:self
selector:@selector(updateLocation)
userInfo:nil
repeats:YES];
updateLocation 开始更新位置,当收到位置时,它会停止更新位置以节省电池。
应该如何完成这个后台任务?对于防止 600 秒后杀死我的应用程序有什么帮助吗?
非常感谢!
I'm developing an app that needs background task updating location every 30 mins.
I've tried to use a NStimer and updating every minute and it works (it spent 2 hours working). However, when I set it for 30 mins, iOS kills my app after 10 mins.
The log says:
Sun Oct 16 11:29:47 unknown SpringBoard[32] <Warning>: MyApp[315] has active assertions beyond permitted time:
{(
<SBProcessAssertion: 0xbb34040> identifier: UIKitBackgroundCompletionTask process: MyApp[315] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:315 preventSuspend preventIdleSleep
)}
Sun Oct 16 11:29:47 unknown SpringBoard[32] <Warning>: Forcing crash report of WhereAreYouReg[315]...
Sun Oct 16 11:29:48 unknown SpringBoard[32] <Warning>: Finished crash reporting.
My background task is started with this code:
backgroundTaskIdentifier = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
// If you're worried about exceeding 10 minutes, handle it here
}];
theTimer=[NSTimer scheduledTimerWithTimeInterval:30*60.0
target:self
selector:@selector(updateLocation)
userInfo:nil
repeats:YES];
updateLocation starts updating location and when location is received, it stops updating location for saving battery.
How is supposed to do this background task? Any help for prevent killing my app after 600 secs?
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。无法创建运行时间超过 10 分钟的后台任务。
You can't. There is no way to create a background task running longer than 10 minutes.