1

I am facing a weird issue in my application when my app goes into Background mode and when iPad gets locked. Till then its working fine but while I am unlocking the device and opening the app from background, its crashing.

This is the Crash log, I am getting from device

Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Exception Note:  SIMULATED (this is NOT a crash)
Highlighted by Thread:  8

Application Specific Information:
<BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1> has active assertions beyond permitted time: 
{(
    <BKProcessAssertion: 0x12cd1e3b0> id: 540-72C6AF6C-F674-40E8-BA89-EFE4BF52F8D6 name: Called by UIKit, from <redacted> process: <BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1> permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:540 preventSuspend  preventIdleSleep  preventSuspendOnSleep 
)}

Elapsed total CPU time (seconds): 82.430 (user 82.430, system 0.000), 23% CPU 
Elapsed application CPU time (seconds): 77.475, 21% CPU

Filtered syslog:
None found

My app has continuous dot animation on screen like rainfall effect based on data from DB which is being synced with Server.

Any help will be highly appreciated. Thanks in advance!!

Jen Jose
  • 3,995
  • 2
  • 19
  • 36
  • Possible duplicate of [iOS7: background task ("myapp" has active assertions beyond permitted time)](http://stackoverflow.com/questions/22679845/ios7-background-task-myapp-has-active-assertions-beyond-permitted-time) – Ali Beadle Aug 08 '16 at 17:01
  • @Ali Beadle : I am not executing any background tasks! I am just running a timer every minute for fetching web service data. So I think my issue is something different.. – Jen Jose Aug 09 '16 at 05:43
  • As @Dhabesh says, that error relates to background tasks. So something is running in the background, even if you did not intend it to. – Ali Beadle Aug 09 '16 at 05:46

2 Answers2

3

As looking into your crash log I am sure that the reason behind your crash is due to a background fetch still in process after 3 mins (180 seconds).

So if I am not wrong after 3 mins it will kill your app and while you reopen it its already in the crash mode so it will not run directly.

I am facing the same issue in my app so to resolve this issue I have to begin background task in my code through AppDelegate like this:

[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];

and then we need to end that task in the Application delegate method

- (void)applicationDidEnterBackground:(UIApplication *)application {

    __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
                [application endBackgroundTask:bgTask];
                bgTask = UIBackgroundTaskInvalid;
        //Save your state or data while invalidating bgTask.

        }];
}

and that's why in your crash report apple clearly mentions that OS only allows any task in the background for 3 mins only!

Check your crash:

Application Specific Information:
    <BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1> has active assertions beyond permitted time: 
    {(
        <BKProcessAssertion: 0x12cd1e3b0> id: 540-72C6AF6C-F674-40E8-BA89-EFE4BF52F8D6 name: Called by UIKit, from <redacted> process:  <BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1>  permittedBackgroundDuration: 180.000000  reason: finishTask owner  pid:540 preventSuspend  preventIdleSleep  preventSuspendOnSleep 
    )}

permittedBackgroundDuration: 180.000000 reason: finishTask owner

means we have only 180 seconds to perform any task in the background as mention here in apple documentation.

if you still require more time to execute your task so you need to enable your app background mode with specific reason otherwise apple may reject your app.

Hope this will help to resolve your crash.

CodeChanger
  • 7,953
  • 5
  • 49
  • 80
  • Agreed with Dhanesh. – Milan V. Aug 09 '16 at 05:39
  • I am not having any background tasks but I am executing Timers for fetching data from web service.. – Jen Jose Aug 09 '16 at 05:40
  • yes that is also one kind of process and if you need any service calling in background you need to use `NSURLSession` with Background Task otherwise it will not allowed to run services in background after 3 min. – CodeChanger Aug 09 '16 at 05:45
  • This solved my problem! I invalidated the web service calling timers in the above method and started them again while app came into Foreground. A million thanks to you ! – Jen Jose Aug 09 '16 at 10:07
0

Well that's reading like a memory dump or a script runtime error. Sorry if it seems a little obvious but have you checked to see if it's allowed to run in the background while the device is locked? you can find it under permissions

  • There is no requirement of any work in the background thread. So I have not added any permissions for Background mode in Capabilities. – Jen Jose Aug 08 '16 at 13:54