iOS Killing my background task after 600 secs

2.1k Views Asked by At

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!

1

There are 1 best solutions below

2
ckruse On BEST ANSWER

You can't. There is no way to create a background task running longer than 10 minutes.