简体   繁体   English

iOS 600秒后杀死我的后台任务

[英]iOS Killing my background task after 600 secs

I'm developing an app that needs background task updating location every 30 mins. 我正在开发一个每30分钟需要后台任务更新位置的应用程序。 I've tried to use a NStimer and updating every minute and it works (it spent 2 hours working). 我已经尝试使用NStimer并更新每一分钟并且它有效(它花了2个小时工作)。 However, when I set it for 30 mins, iOS kills my app after 10 mins. 但是,当我将其设置为30分钟时,iOS会在10分钟后杀死我的应用程序。

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. updateLocation开始更新位置,当收到位置时,它会停止更新位置以节省电池电量。

How is supposed to do this background task? 怎么应该做这个后台任务? Any help for prevent killing my app after 600 secs? 任何帮助防止在600秒后杀死我的应用程序?

Thank you very much! 非常感谢你!

You can't. 你不能。 There is no way to create a background task running longer than 10 minutes. 无法创建运行时间超过10分钟的后台任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM