iOS7: background task ("myapp" has active assertions beyond permitted time)

jake85 picture jake85 · Mar 27, 2014 · Viewed 9.6k times · Source

crash report detail :

Hardware Model:      iPhone5,2
Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread:  3

Application Specific Information:
MyApp[1369] has active assertions beyond permitted time: 
{(
<BKProcessAssertion: 0x175ca7d0> identifier: Called by MyApp, from -[AppDelegate applicationDidEnterBackground:] process: MyApp[1369] permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:1369 preventSuspend  preventIdleSleep      preventSuspendOnSleep 
)}

thread 3 :

Thread 3 name:  com.apple.NSURLConnectionLoader
Thread 3:
0   libsystem_kernel.dylib          0x3937ea50 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3937e848 mach_msg + 36
2   CoreFoundation                  0x2e61261c __CFRunLoopServiceMachPort + 152
3   CoreFoundation                  0x2e610d3c __CFRunLoopRun + 788
4   CoreFoundation                  0x2e57b7a4 CFRunLoopRunSpecific + 520
5   CoreFoundation                  0x2e57b586 CFRunLoopRunInMode + 102
6   Foundation                      0x2efbb23c +[NSURLConnection(Loader)     _resourceLoadLoop:] + 316
7   Foundation                      0x2f030a0a __NSThread__main__ + 1058
8   libsystem_pthread.dylib         0x393f8956 _pthread_body + 138
9   libsystem_pthread.dylib         0x393f88c6 _pthread_start + 98
10  libsystem_pthread.dylib         0x393f6ae4 thread_start + 4

my app using background task with this code at "applicationDidEnterBackground" :

// 10min background task
UIBackgroundTaskIdentifier myLongTask;
myLongTask = [[UIApplication sharedApplication]
              beginBackgroundTaskWithExpirationHandler:^{
                  [locationMgrInstance timerSet];
              }];
// cell change  
[locationMgrInstance startMonitoringSignificantLocationChanges];

it works good at iOS 6... but! iOS 7 throw assert after 180 sec. help!

Answer

Paulw11 picture Paulw11 · Mar 27, 2014

This message indicates that your background task ran for too long. iOS7 has changed some aspects of background processing. In particular a background task should complete in a short amount of time and if it doesn't your app is terminated. You need to look at how your background tasks are operating. In particular, you need to ensure that you call [[UIApplication sharedApplication] endBackgroundTask:task]; in a timely manner. You should also call this method in your expiration handler.

Have a look at the Background Execution and Multitasking section in the Apple iOS App Programming Guide Background Execution Guide.

Additionally, you can check [[UIApplication sharedApplication]backgroundTimeRemaining] - on iOS 6 this started at 10 minutes. In iOS 7 it starts at 3 minutes - which is why you are getting timed out after 180 seconds. You need to re-evaluate your background strategy to deal with the new limit.